I have written an implementation of the unity interface IInterceptionBehavior to do some logging. It has a dependency on an ILog to do the logging.
public class InterceptionLoggingBehavior : IInterceptionBehavior {
public InterceptionLoggingBehavior(ILog log) {...}
...
}
I also have a ConsoleLog that implements ILog.
I am trying to resolve an interface that uses the logging interface interceptor, but it cannot find the ILog. Trying to resolve the InterceptionLoggingBehavior directly does not work even though I can get unity to resolve the ILog directly:
UnityContainer container = ...
var l = container.Resolve<com.InsightSoftware.LoggingAPI.ILog>();
var b = container.Resolve<com.InsightSoftware.Logging.InterceptionLoggingBehavior>();
var p = container.Resolve<com.InsightSoftware.MetadataAPI.ITableIdentityProvider>();
Resolving the ILog (on the second line) works fine, but resolving the InterceptionLoggingBehavior on the 3rd line or the ITableIdentityProvider (the interface that I am trying to log) on the 4th line gets the error:
The current type, com.InsightSoftware.LoggingAPI.ILog, is an interface and cannot be constructed. Are you missing a type mapping?
My Question: Can anyone tell me why unity cannot resolve the ILog when it is a dependency for InterceptionLoggingBehavior?
The xml that I am using to configure unity, including the mapping:
<unity xmlns="http://ift.tt/1g8Zbje">
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />
<alias alias="ILog" type="com.InsightSoftware.LoggingAPI.ILog, com.InsightSoftware.LoggingAPI"/>
<alias alias="ConcreteLog" type="HubbleSandbox.ConsoleLog, HubbleSandbox" />
<alias alias="InterceptionLoggingBehavior" type="com.InsightSoftware.Logging.InterceptionLoggingBehavior, com.InsightSoftware.Logging" />
<!--More aliases-->
<containers>
<container>
<extension type="Interception" />
<!-- The type mapping that I expect to be resolved. -->
<register type="ILog" mapTo="ConcreteLog" />
<register type="ITableIdentityProvider" mapTo="TableIdentityProvider">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="InterceptionLoggingBehavior" />
</register>
<!--More registrations-->
</container>
</containers>
(note that I never explicitly register InterceptionLoggingBehavior, I think that it gets implicitly registered by using it in the interceptionBehavior tag.)
I've also tried configuring unity in code (not using a config file) like so:
UnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<ILog, ConsoleLog>();
container.RegisterType<ITableIdentityProvider, TableIdentityProvider>(
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<InterceptionLoggingBehavior>());
// more registrations
var l = container.Resolve<ILog>();
var b = container.Resolve<ITableIdentityProvider>();
but I still get the same error.
No comments:
Post a Comment