惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Vercel News
Vercel News
U
Unit 42
L
LangChain Blog
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
F
Fortinet All Blogs
小众软件
小众软件
I
InfoQ
P
Proofpoint News Feed
D
DataBreaches.Net
Martin Fowler
Martin Fowler
H
Help Net Security
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog

博客园 - 无名365

.NET 2.0 JSON Parser Provisioning 是什么意思? SOA与云计算 Good understand on WCF Data Contract & Serialization WCF DataContract EmitDefaultValue a xml configuration for unity and interception Programmatically Compress and Decompress Files using c# CodeRun Studio - A free cloud develop and debug service for .Net Cloud IDE 10个最“优秀”的代码注释 Compress and Decompress JQuery Mobile 1.0 Released, Gets Mixed Reaction Interceptor in Unity and Policy Injection in Unity Unity Configuration Node Unity Configuration from Separate Configuration File IoC and Unity - Configuration Objects and the Art of Data Modeling AppFabric Cache - Cache Cluster EF - How to delete an object without retrieving it LINQ to SQL Extension: Batch Deletion with Lambda Expression
Configuring Unity Container with Policy Injection Configu...
无名365 · 2011-11-22 · via 博客园 - 无名365

2011-11-22 13:45  无名365  阅读(251)  评论()    收藏  举报

Recently while preparing a presentation on Policy Injection Application block integration with Unity, I struggled with configuring the unity container to understand for PIAB configuration. Hence, thought of writing it here. This blog post talks about, How to configure Unity container to understand PIAB configuration(Policies, Call Handlers, Maching Rules) so that, we can utilize the Policy Based AOP provided by PIAB.

Below is the code from my sample, Here I am configuring a simple business object BOImplementation which implements IBOInterface.

IUnityContainer container = new UnityContainer();

            //Interception is provided as an extension to Unity, Hence need to add this extension to the container

            container.AddNewExtension<Interception>();

            //Get Policy Injection Settings from the Configuration

            IConfigurationSource configSource = ConfigurationSourceFactory.Create();

            PolicyInjectionSettings policyInjectionsettings = (PolicyInjectionSettings)configSource.GetSection(PolicyInjectionSettings.SectionName);

            //Register Type with the container

            container.RegisterType<IBOInterface, BOImplementation>();

            //Configure the container for Interception on given interface (IBOInterface in this case)

            //Here I am using TransparentProxyInterceptor, you can choose from

            //InterfaceInterceptor, TransparentProxyInterceptor or VirtualMethodInterceptor, depending upon the requirement

            container.Configure<Interception>().SetInterceptorFor<IBOInterface>(new TransparentProxyInterceptor());

            // Apply Polocy Injection Settings to the container

            if (policyInjectionsettings != null)

            {

                policyInjectionsettings.ConfigureContainer(container, configSource);

            }

Now, when I try to resolve the business object instance, I get a Transparent Proxy instead of a real object.

IBOInterface businessObject = container.Resolve<IBOInterface>();

businessObject is a transparent proxy, If there exists a policy which applies to  BOImplementation In the PIAB configuration. Hence the interception mechanism is in place to provide your call handler a chance to do the AOP for you.