Help us understand the problem. What is going on with this article?

Prism 6.3でAOPを使う方法

More than 1 year has passed since last update.

問題

Prism 6.3 + Unityを使用していて、AOPをやろうと思い、最新のUnity.Interceptionパッケージ 5.5.3をNugetから取得。しかし、AOPのクラスが参照できない。

解決方法

Prism6.3で参照しているUnityが古いことが判明。Interceptionパッケージ 4.0.1をNugetから取得することで解決。
どうやらPrism6.3は4系のUnityと依存関係がある様子。
さらには4系と5系で破壊的変更が起きているようで名前空間が違う。

4系
~~~ C#
Microsoft.Practices.Unity.InterceptionExtension
~~~

5系

Unity.Interception

サンプルコード。PrismのBootStrapper。jobsRepositoryのメソッド呼び出し時にLogBehaviorを呼ぶように設定。サンプルコードなので、CreateShellでjobsRepositoryを呼び出していますが、実際にはこんなところで呼び出しません。

using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

    class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {

            Container.AddNewExtension<Interception>();
            Container.RegisterType<jobsRepository>(new Interceptor<VirtualMethodInterceptor>()
                                         , new InterceptionBehavior<LogBehavior>());

            var jobsRepo = Container.Resolve<jobsRepository>();
            jobsRepo.GetJobs();
            return Container.Resolve<MainWindow>();
        }
     }
using Microsoft.Practices.Unity.InterceptionExtension;

    public class LogBehavior : IInterceptionBehavior
    {
        public bool WillExecute => true;

        public IEnumerable<Type> GetRequiredInterfaces()
        {
            return Enumerable.Empty<Type>();
        }

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            Debug.WriteLine("開始: " + input.MethodBase.Name);

            var result = getNext()(input, getNext);

            Console.WriteLine($"終了:{input.MethodBase.Name}");

            return result;
        }
    }
shin1103@github
某SIerでシステムエンジニアをやっています。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした