アプリケーションで使用しようとしInterception
ていMVC
ます。私が抱えている問題は、コントローラーにあります。コントローラーがUnity
コンテナーに登録されており、インターフェイスがないため、エラーが発生しています。コントローラーをプロセスから除外する方法が必要だと思いますInterception
か、それとも何か他のことができますか? これは可能ですか、実行可能ですか?SO で同様の質問をしましたが、受け取ったコメントに基づいて、別の質問を作成するのが最善だと感じています。
エラーは次のとおりです。
例外情報: 例外の種類: ResolutionFailedException 例外メッセージ: 依存関係の解決に失敗しました。タイプ = "CSR.Presentation.Controllers.HomeController"、名前 = "(none)"。例外が発生しました: コンストラクター Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior(Microsoft.Practices.Unity.InterceptionExtension.CurrentInterceptionRequestinterceptionRequest、Microsoft.Practices.Unity.InterceptionExtension.InjectionPolicy[] ポリシー、Microsoft.Practices.Unity.IUnityContainer コンテナー) を呼び出しています。例外: ArgumentException - 渡される型はインターフェイスでなければなりません。
コードは次のとおりです。
// FIRST
container.RegisterTypes(
AllClasses.FromLoadedAssemblies(),
WithMappings.FromMatchingInterface,
WithName.Default,
WithLifetime.ContainerControlled,
t => new InjectionMember[] {
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<PolicyInjectionBehavior>()});
// SECOND
container.AddNewExtension<Interception>();
// THIRD
var first = new InjectionProperty("Order", 1);
var second = new InjectionProperty("Order", 2);
container.Configure<Interception>()
.AddPolicy("logging")
.AddMatchingRule<NamespaceMatchingRule>(
new InjectionConstructor(
new InjectionParameter("CSR.*")))
.AddCallHandler<LoggingCallHandler>(
new ContainerControlledLifetimeManager(),
new InjectionConstructor(),
first);
// Controller ==> execution doesn't reach here using interception
public class HomeController : Controller
{
public ActionResult Index()
{
return View("Index");
}
}