Is there any equivalent to the Registry class from StructureMap in Unity?
I like to think about a layer/component/library to configure it self - thus populating the container. So the "parent" layer will just need to know about the Registration class.
No, there isn't. In our current project we have manually mimic'd the concept of a Registry although our implementation isn't nearly as powerful as a StructureMap Registry.
If all you are wanting is modularized container configuration, what you could do is create a marker interface (maybe IRegistry) and then have your application scan for IRegistry classes. With Unity, you can resolve classes that haven't been registered into Unity yet, so you could simply resolve each IRegistry implementation as you find it. The registry classes could take the container as a constructor parameter and then each class could configure the container as needed for that layer/component/library.
public interface IRegistry
{
void Configure();
}
public class ServicesRegistry : IRegistry
{
public ServicesRegistry(IUnityContainer container)
{
_container = container;
}
public sub Configure()
{
// Configure container for layer
}
}
Now in your app startup somewhere you could have an application bootstrapper that either knows about all your registries or knows how to scan for them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With