Saturday, January 10, 2015

StructureMap struggles with log4net?

StructureMap Exception Code: 202
No Default Instance defined for PluginFamily log4net.ILog, log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a

 
 

This error appears when a dependency which uses log4net rears its head the wrong way in the .Initialize wire up. Here is how the something is wired up to work properly instead. I'm using StructureMap 3.1.0.133 and StructureMap.Net4 3.1.0.133 is also in the mix, but I don't see it in the using declarations at the top of Global.asax so perhaps it is not used.

ObjectFactory.Initialize(maps =>
{
   maps.For<IFoo>().Singleton().Use<Foo>();
   maps.For<IBar>().Singleton().Use<Bar>();
   maps.For<ISomething>().AlwaysUnique().Use(s => new
         Something(LogManager.GetLogger(s.ParentType ?? s.RootType)));
});

No comments:

Post a Comment