Search code examples
c#asp.net.netnancy

Nancy Modules are globally discovered, how to implement the same idea with .net?


I have a web api project, and I have a HttpSelfHost server. I know that when using NancyFX you can use Nancy.Self.Host to host a server and then make calls to the API which extends NancyModule, I got 2 questions.

  1. How does Nancy see the api module if its in a different project?

  2. How do I implement the same idea without Nancy? the idea is:

having an API project, and having a server project, how could I run the server, and then send requests with the API routes?

any help\tip would be appreciated!


Solution

  • NancyFX can do that discovering all the assemblies in his working directory and looking for class who extend NancyModule through reflection. NancyFX use an IoC container to collect the modules.

    I suggest you to check NancyFXcode on github especially the boostrapper and the Nancy Boostrapper who use TinyIoC as IoC container.

    EDIT:

    Looking that code you should be able to replicate the feature you need.

    It can be you need less infrastructure to load classes dynamically. I suggest you to look at System.Reflection namespace. With that you can load assemblies dynamically and search the classes implementing a known interface or they have a known prefix.