WCFサービスをホストしているMVCアプリケーションでインターセプタを動作させるのに苦労しています。Castle Windsor WCFインターセプタ
属性で装飾されたクラス/メソッドを使用してAOPをきめ細かく制御したいと思っていますが、WCF機能を使用してインターセプタが呼び出されることはありません。 Global.asax
で
私が持っている:
container = new WindsorContainer();
container.AddFacility<WcfFacility>();
container.Kernel.ComponentModelBuilder.AddContributor(new RequireAspects());
container.Install(FromAssembly.This());
RequireAspects
配線アップインターセプタ:
public class RequireAspects : IContributeComponentModelConstruction
{
if (Attribute.IsDefined(model.Implementation, typeof(CacheAttribute)))
{
model.Interceptors.Add(InterceptorReference.ForType(typeof(Caching)));
}
}
インターセプタはそうのようになります。
public class CacheAttribute : Attribute { };
public class Caching : IInterceptor
{
...
}
サービス:
[Cache]
public class TestService : ITestService
{
...
}
の
そして最後にサービスがインストールされています
public class ServicesInstaller : IWindsorInstaller
{
public void Install(Castle.Windsor.IWindsorContainer container,
Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
container.Register(AllTypes.FromThisAssembly()
.InNamespace("Test.Services")
.Configure((c => c.LifestyleTransient())));
}
}
サービス構成:
<system.serviceModel>
<services>
<service name="Test.Services.TestService">
<endpoint address=""
binding="webHttpBinding"
contract="Test.Services.ITestService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
インターセプターは明らかに追加され、プロキシが作成されますが、インターセプタが呼び出されることはありません。
WCFでこのインターセプタの動作例を見直しましたが、私のユースケースを満たしていません。
https://github.com/RussellPolitzky/Castle-Windsor-WCF-Service-With-Interceptor-and-Meta-Data-Publishing
上記のコードは、MVCとライブラリでAOPを使用する他のすべてのケースで機能します。
.svcファイルまたはサービスをインスタンス化するコードを表示してください。 –
申し訳ありません。それはDefault Factoryを使用しています。 <%@ ServiceHost Language = "C#" Debug = "true" Service = "Services.TestService" CodeBehind = "TestService.svc.cs" Factory = "Castle.Facilities.WcfIntegration.DefaultServiceHostFactory、Castle.Facilities.WcfIntegration"%> – SSmith