Question

So I have a Unity.WebApi installed on my MVC Application. There is also a web api section in a folder called "Areas".

I'm in the process of wiring things up to implement caching via policy injection and attributes on the Web Api.

Here's my Bootstrapper.cs class:

public static void Initialise(IUnityContainer theContainer)
{
    var container = BuildUnityContainer(theContainer);

    GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
}

private static IUnityContainer BuildUnityContainer(IUnityContainer theContainer)
{
    theContainer.RegisterType<IPatientSearchController, PatientSearchController>(
            new InterceptionBehavior<PolicyInjectionBehavior>(),
            new Interceptor<InterfaceInterceptor>());

    // register all your components with the container here
    // e.g. container.RegisterType<ITestService, TestService>();            

    return theContainer;
}

And in the global.asax I have this:

IUnityContainer container = Application.GetContainer();
container.AddNewExtension<Interception>();

ContainerBootstrapper.RegisterTypes(container);
Bootstrapper.Initialise(container);

I already have the cachingAttribute and cachingCallHandler implemented. And I want to be able to attribute my webapi methods so they have caching ability.

[caching]
public int GetNumber() 
{
    return 5;
}

I believe I have most things correctly implemented here. But I keep getting this error when I access the api method from the URL

Type passed must be an interface. System.ArgumentException

at System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle) at System.RuntimeType.GetInterfaceMap(Type ifaceType) at Microsoft.Practices.Unity.InterceptionExtension.InterfaceInterceptor.d__0.MoveNext() at Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior..ctor(CurrentInterceptionRequest interceptionRequest, InjectionPolicy[] policies, IUnityContainer container) at lambda_method(Closure , IBuilderContext ) at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.<>c_DisplayClass1.b_0(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey, Action1 childCustomizationBlock) at Microsoft.Practices.Unity.InterceptionExtension.InterceptionBehaviorsPolicy.<GetEffectiveBehaviors>d__4.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Microsoft.Practices.Unity.InterceptionExtension.InstanceInterceptionStrategy.PostBuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top