Reputation: 5938
I have a class Library containing some services.
Using structure map i want these services to be registered in that class library. This results in assemblies using this class library should not set dependencies up for this class library but simply call a module that sets this up within the library itself.
For example is this possible to do using autofac. Lets say i have a class library with IAAAService and IBBBService. Using autofac i can in this class library do the following:
public class AutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<AAAService>().As<IAAAService>();
builder.RegisterType<BBBService>().As<IBBBService>();
}
}
And from the assembly that should use the library i can do this:
builder.RegisterModule(new AutofacModule());
I am in a situation where i am bound to use structure map and i want to do something similar.
Is this possible in structure map? If so how would i do that?
Thanks :)
Upvotes: 2
Views: 1125
Reputation: 27861
In StructureMap, there is a similar concept called a Registry. Take a look here for more details: http://structuremap.github.io/registration/
Please note though that I do not recommend that you use the container inside your class libraries. Containers should only be used inside applications (if they are to be used at all).
Quoting from this article:
A DI Container should only be referenced from the Composition Root. All other modules should have no reference to the container.
Upvotes: 2