Im using StructureMap for IoC, im getting Configuration from App.Config, like this:
public class ImplementationFactory
{
private static volatile ImplementationFactory Factory;
private static object syncRoot = new Object();
private ImplementationFactory()
{
}
public static ImplementationFactory Instance
{
get
{
if (Factory == null)
{
lock (syncRoot)
{
if (Factory == null)
{
Factory = new ImplementationFactory();
}
}
}
return Factory;
}
}
Programmer prog;
public Contracts.IImplementation GetImplementation()
{
if (this.prog == null)
{
ObjectFactory.Initialize(x => x.PullConfigurationFromAppConfig = true);
prog = ObjectFactory.GetInstance<Programmer>();
}
return prog.Implementation;
}
}
[Pluggable("Default")]
[PluginFamily("Default")]
internal class Programmer
{
public readonly Contracts.IImplementation Implementation;
public Programmer(Contracts.IImplementation Implementation)
{
Implementation = Implementation;
}
}
now instead of Providing the two assembly names by App.Config i want to just provide them by code like from variables , any idea how can i change my code to do that ?
Here is the solution:
first make your own registry which inherits extend Registry :
now you need to initialize the container(replace code in the question with this one) :
this shall work…