I'm using StructureMap in an asp.net mvc 5 application, I have a lot of services, and for each service I have an interface and a class so for example I have an IUserService and a UserService, the interfaces are in a different namespace than the actual service class, the interfaces are in the namespace 'Services.Interfaces' and the service classes are in namespace 'Services', StructureMap works fine to find the service for the interface, but when I want to get an instance explicitly by using
var container = Ioc.Initialize();
var userService = container.GetInstance<IUserService>();
I'm getting an error 'No default Instance is registered and cannot be automatically determined for type 'Services.Interfaces.IUserService'
why does this happen only when calling GetInstance and how can I resolve this?
I'm using the defalt configuration like this:
public static class IoC {
public static IContainer Initialize() {
return new Container(c => c.AddRegistry<DefaultRegistry>());
}
}
public DefaultRegistry() {
Scan(
scan => {
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.With(new ControllerConvention());
});
//For<IExample>().Use<Example>();
}