所以我在我的MVC应用程序上安装了Unity.WebApi。 在名为“Areas”的文件夹中还有一个web api部分。
我正在通过策略注入和Web Api上的属性来连接实现缓存。
这是我的Bootstrapper.cs类:
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;
}
在global.asax我有这个:
IUnityContainer container = Application.GetContainer();
container.AddNewExtension<Interception>();
ContainerBootstrapper.RegisterTypes(container);
Bootstrapper.Initialise(container);
我已经实现了cachingAttribute和cachingCallHandler。 我希望能够将我的webapi方法归因于它们具有缓存能力。
[caching]
public int GetNumber()
{
return 5;
}
我相信我在这里正确实施了大部分内容。但是当我从URL
访问api方法时,我一直收到此错误传递的类型必须是接口。 System.ArgumentException
在Microsoft.Practices.Unity.InterceptionExtension的Microsoft.Practices.Unity.InterceptionExtension.InterfaceInterceptor.d__0.MoveNext()中的System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle handle,RuntimeTypeHandle interfaceHandle)处于System.RuntimeType.GetInterfaceMap(Type ifaceType)。 .PolicyInjectionBehavior..ctor(CurrentInterceptionRequest interceptionRequest,InjectionPolicy []策略,IUnityContainer容器)位于Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext的lambda_method(Closure,IBuilderContext)。&lt;&gt; c_ DisplayClass1.b _0( Microsoft.Practices上的Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)中的Microsoft.Practices.ObjectBuilder2.BuildPrateStrategy.PreBuildUp(IBuilderContext context)上的Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext上下文)中的IBuilderContext上下文。 ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey,A来自Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)的Microsoft.Practices.Unity.InterceptionExtension.InstanceInterceptionStrategy.PostBuildUp(IBuilderContext context)中的ction
1 childCustomizationBlock) at Microsoft.Practices.Unity.InterceptionExtension.InterceptionBehaviorsPolicy.<GetEffectiveBehaviors>d__4.MoveNext() at System.Linq.Buffer
1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable
1 source)在Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t,Object existing,String name,IEnumerable`1 resolverOverrides)