StructureMap is an IoC/DI container for .Net which has been a long time around. I’ve been using it for these past few years, and after all this time, I found out the correct way to implement it.
This is how I used it before and I’m sure the majority of you are currently using the same methods. In the Registry, I would register each interface and it’s inherited class by calling a “config.for” for each service as follows:
config.For(typeof(ITestService)).Add(typeof(TestService)); config.For(typeof(IUserService)).Add(typeof(UserService)); config.For(typeof(ITenantService)).Add(typeof(TenantService)); config.For(typeof(IProjectService)).Add(typeof(ProjectService));
And whenever new interfaces and services are added, they need to be registered using a new “config.for” line.
That was the old way, of how I did things. This is the new way. Continue reading