StructureMap , , StructureMap, , .
StructureMap 2.6.2, 2.5+, .For < > (). < > ().
public class CommonsRegistry : Registry
{
public CommonsRegistry()
{
For<ILogger>().AlwaysUnique().Use(s => s.ParentType == null ? new Log4NetLogger(s.BuildStack.Current.ConcreteType) : new Log4NetLogger(s.ParentType.UnderlyingSystemType.Name));
XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(GetType()).Location), "Log.config")));
}
}
, ILogger , , , - , /context.
* , (XmlConfigurator.ConfigureAndWatch) Log4Net, "Log.config" , , .
, , IOC.Startup, , .
ObjectFactory.Initialize(x =>
{
x.AddRegistry<CommonsRegistry>();
...
}
, , , , - .
class foo
{
private readonly ILogger _log;
public foo(ILogger log)
{
_log = log;
}
}
/ "foo".