I'm not too familiar with StructureMap, but I can guess at what that code is doing. Mostly. StructureMap has the concept of Registries, which are classes used to initialize the container. Unity doesn't have a Registry concept, it just has a direct container
API. If you wish to keep the idea of a registry type where you put your initialization logic, I've had a lot of luck lately using Unity extensions to do this.
To create the extension, do this:
public class MyRegistry : UnityContainerExtension
protected override void Initialize()
// use container API here to register your types0
To add it to the container, do:
Unity doesn't have an equivalent of the AssertConfigurationIsValid method, so you'll have to do without that one, but that method is for diagnostics anyway, so you're ok without it.
As for the details of registration, the "For<interface>.lifetime().Use<impl>()" form of APIs in StructureMap end up in Unity as:
Where you need to pick the appropriate LifetimeManager class to match what you were doing in StructureMap. If you don't give a lifetime manager, Unity defaults to Transient. I believe StructureMap defaults to what we call PerResolveLifetimeManager. Singleton
corresponds to ContainerControlledLifetimeManager. I'm not familiar with what that HybridHttpOrThreadLocalScoped does, but I expect we don't have a direct analogue, but if you tell me what it does it'll be pretty easy to replicate in a custom lifetime.
Also, what does AddInstances do?
Anyway, you can either call these directly on an instance of IUnityContainer, or if you want to go the separate registry route via an extension above, just call those methods on the Container property of the extension. That'll get the container set up.
Oh, also, if you're using any of the assembly scanning stuff in StructureMap, we don't have a pre-written analogue to that stuff, but it's pretty easy to write something similar, you just need to do it once and it's done.
Hope this helps,