I'm dealing with structuremap error for quite a while. The error is:
StructureMap.StructureMapException: StructureMap Exception Code: 202 No Default Instance defined for PluginFamily SomeNamespace.ISomeInterface, SomeNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Our project is fully multithreaded and StructureMap can be called several times per second with different profile name each time.
StructureMap setting is done when application starts. I use the StructureMap.Configuration.DSL.Registry:
var registry = new Container(...some parameters settings...);
StructureMap.ObjectFactory.Configure(x => x.IncludeRegistry(registry));
And Container is:
class Container : StructureMap.Configuration.DSL.Registry
{
public Container(...Some settings parameters...)
{
For<IConnG>().Use<DG>()
.Ctor<string>("user").Is(some parameter)
.Ctor<string>("pass").Is(some parameter)
.Ctor<string>("site").Is(some parameter)
.Ctor<string>("DateFormat").Is(some parameter);
For<IRPG>().Use<RPG>();
Scan(asm =>
{
asm.TheCallingAssembly();
asm.Include(type => type.IsAbstract == false && type.IsSubclassOf(typeof(BaseC)));
asm.With(new RegistrationConvention());
});
var actionName = (enumA)Enum.Parse(typeof(enumA), some parameter);
switch (actionName)
{
case enumA.ActionA:
Profile(enumA.ActionA.ToString(), (pe) =>
{
pe.For...;
pe.For...;
pe.For...;
pe.For<IXXX>().Use<DefaultXXX>();
**pe.For<IAction<SomeNamespace.SearchParams, SomeNamespace.SearchParams>>().Use<DefaultSearchParams>();**
pe.For...;
});
break;
case enumA.ActionB:
Profile(enumA.ActionB.ToString(), (pe) =>
{
pe.For...;
pe.For...;
pe.For...;
pe.For<IXXX>().Use<DefaultXXX>();
**pe.For<IAction<SomeNamespace.SearchParams, SomeNamespace.SearchParams>>().Use<DefaultSearchParams>();**
pe.For...;
});
break;
case enumA.ActionC:
Profile(enumA.ActionC.ToString(), (pe) =>
{
pe.For...;
pe.For...;
pe.For...;
pe.For<IXXX>().Use<DefaultXXX>();
**pe.For<IAction<SomeNamespace.SearchParams, SomeNamespace.SearchParams>>().Use<XXXSearchParams>();**
pe.For...;
});
break;
case enumA.ActionD:
Profile(enumA.ActionD.ToString(), (pe) =>
{
pe.For...;
pe.For...;
pe.For...;
pe.For<IXXX>().Use<DefaultXXX>();
**pe.For<IAction<SomeNamespace.SearchParams, SomeNamespace.SearchParams>>().Use<DefaultSearchParams>();**
pe.For...;
});
break;
}
}
}
The RegistrationConvention is:
public class RegistrationConvention : StructureMap.Graph.IRegistrationConvention
{
#region IRegistrationConvention Members
public void Process(Type type, StructureMap.Configuration.DSL.Registry registry)
{
var interfaces = new List<Type>
{
type.GetInterface("IInfo`1"),
type.GetInterface("IBook`1"),
type.GetInterface("IConf`1"),
type.GetInterface("IClxP`1"),
type.GetInterface("ICanc`1"),
type.GetInterface("IConf2`1"),
type.GetInterface("IMaxP`1"),
type.GetInterface("IAction`1")
};
interfaces
.ForEach(contractType =>
{
if (contractType != null)
{
registry.For(contractType).Use(type);
}
});
}
#endregion
}
I'm calling StructureMap in code like that:
var container = StructureMap.ObjectFactory.Container;
container.SetDefaultsToProfile(Some profile name);
var adaptor = container.GetInstance<IAction<SomeNamespace.SearchParams, SomeNamespace.SearchParams>>();
This code is called by many threads, and I'm getting this error not all the times, but quite a lot. When printing out WhatDoIHave() it indicates it has it.
I'll be glad to have any suggestion/correction. Thanks in advance.