They use StructureMap for IoC where I am currently working.
I have an application class that will implement multiple properties of the same interface...and I need to bind DIFFERENT IMPLEMENTATIONS
...and no, I cannot do this: IProvider<T>
FOR INSTANCE:
public class MyApplication
{
[SetterProperty]
public IProvider OneProvider { get; set; }
[SetterProperty]
public IProvider TwoProvider { get; set; }
}
public class FooProvider: IProvider {
// I would like to force this one to bind-on OneProvider ...
}
public class BarProvider: IProvider {
// I would like to force this one to bind-on TwoProvider ...
}
In Unity, there are many ways to do this, for instance;
[Dependency("FooProvider")]
public IProvider OneProvider { get; set; }
[Dependency("BarProvider")]
public IProvider TwoProvider { get; set; }
...however, StructureMaps SetterProperty attribute doesnt allow for this.
QUESTION:
How do I bind different implementations into an instance-property?
SAMPLE REGISTRY:
Here is an example of what my registry might look like...
public ContainerRegistry()
{
Scan(
scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.LookForRegistries();
scan.AssembliesFromApplicationBaseDirectory(f => f.FullName.StartsWith("My.Awesome.Company", true, null));
scan.AddAllTypesOf(typeof(IApplication));
scan.AddAllTypesOf(typeof(IManager<>));
scan.AddAllTypesOf(typeof(IProvider));
scan.AddAllTypesOf(typeof(IUnitOfWorkFactory<>));
scan.SingleImplementationsOfInterface();
});
For(typeof(IApplication)).Use(typeof(MyApplication));
}