For the following \"project\" I am getting a very annoying and inexplicable error when resolving Unity for DI.
InvalidOperationException - The type Lo
Activation error occured while trying to get instance of type LogWriter, key ""
check your config file it must have correct default 'loggingConfiguration' section
Try this:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
try
{
IUnityContainer container = new UnityContainer();
container.RegisterType<ILogWriter, LogWriter>();
container.RegisterType<ExceptionManager>();
container.RegisterType<Performance>(new InjectionConstructor(typeof(ILogWriter), typeof(ExceptionManager));
Performance p = container.Resolve<Performance>();
}
catch (Exception ex)
{
}
}
LogWriter does not have an empty constructor or a constructor with all concrete types parameters: LogWriter Constructor.
So Unity fails in building it and as it says, it will need your help by configuring the container to provide an implementation.
As a confirmation, ExceptionManager will probably be resolved ok, since it has only one constructor, parameterless as well :)
In order for Unity to construct your Performance class, it needs to know how to construct the implementation of ILogWriter.
I cannot see anywhere in your code where you tell Unity what class to create for the ILogWriter interface, so I suspect you may need to add this.
You need to add the Enterprise Library extension to your container. Without it, the container doesn't read the config file and therefore doesn't know how to create Entlib objects, like the LogWriter.