I am building a small Nancy web project.
In the method of one of my classes (and not in the nancy module) I would like to basically execute:
var myThing = TinyIoC.TinyIoCContainer.Current.Resolve<IMyThing>();
However, .Current is only one registration in .Current (not public members, _RegisteredTypes), which:
TinyIoC.TinyIoCContainer.TypeRegistration
Naturally, in my code above, I get:
Unable to resolve type: My.Namespace.IMyThing
So, I suppose that I am not getting the same container registered in my boot file?
Is there any way to get to it?
EDIT
Extract a bit more of what I'm trying to do:
Basically, my url structure looks something like this:
/ {MyType} / {MyMethod}
So the idea is that: / customer / ShowAllWithTheNameAlex will load the Customer service and execute the showAllWithTheNameAlex method
How do i do this:
public interface IService { void DoSomething(); IEnumerable<string> GetSomeThings(); }
Then I have an abstract base class with a GetService method that returns a service.
It is here that I am trying to use TinyIoC.TinyIoCContainer.Current.Resolve (); In this case, it will be TinyIoC.TinyIoCContainer.Current.Resolve ("typeName");
public abstract class Service : IService { abstract void DoSomething(); abstract IEnumerable<string> GetSomeThings(); public static IService GetService(string type) {
Here is my service implementation.
public class CustomerService : Service { public void DoSomething() {
Finally, I have a Nancy module that looks like this:
public class MyModule : NancyModule { public MyModule() { Get["/{typeName}/{methodName}"] = p => ExecuteMethod(p.typeName, p.methodName); } private dynamic ExecuteMethod(string typeName, string methodName) { var service = Service.GetService(typeName); var result = service.GetType().GetMethod(methodName).Invoke(service, null);