Hi
I am trying to implement a logger using the Unity Interceptor. It works for classes that do not implement an interface with type parameters but doesnt when interface does contain in and out parameters as below.
MyContainer.Container.RegisterType<IQueryHandler<GetPersonByIdQueryParams, GetPersonByIdResults>, GetPersonByIdQueryHandler>(
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<TraceInterceptor>());
Inteface is defined like so
public interface IQueryHandler<in TParameter, out TResult>: IDisposable where TResult : IQueryResult where TParameter : IQueryParameters
{
/// <summary>
/// Retrieve a query result from a query
/// </summary>
/// <param name="query">Query</param>
/// <returns>Retrieve Query Result</returns>
TResult Retrieve(TParameter query);
}
later in code where I try and resolve :
MyContainer.Container.Resolve<IQueryHandler<TParameter, TResult>>(); // throws this error
Microsoft.Practices.Unity.ResolutionFailedException was unhandled by user code
Message: An exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Microsoft.Practices.Unity.dll but was not handled in user code
Additional information: Resolution of the dependency failed, type = "Aoms.DataAccess.Interfaces.IQueryHandler`2[Aoms.DataAccess.Reads.Feature.Query.GetPersonByAomsIdQueryParams,Aoms.DataAccess.Reads.Feature.QueryResults.GetPersonByAomsIdResults]",
name = "(none)".
Exception occurred while: while resolving.
Exception is: TypeLoadException - Could not load type 'DynamicModule.ns.Wrapped_IQueryHandler`2_46f2924ad274474a9736c37afcfff0a4' from assembly 'Unity_ILEmit_InterfaceProxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because it declares a covariant
or contravariant type parameter and is not an interface or delegate.
-----------------------------------------------
At the time of the exception, the container was:
Resolving Aoms.DataAccess.Reads.Feature.QueryHandlers.GetPersonByIdQueryHandler,(none) (mapped from Aoms.DataAccess.Interfaces.IQueryHandler`2[Aoms.DataAccess.Reads.Feature.Query.GetPersonByIdQueryParams,Aoms.DataAccess.Reads.Feature.QueryResults.GetPersonByIdResults],
(none))
.?