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

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
量子位
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
爱范儿
爱范儿
博客园 - 【当耐特】
Vercel News
Vercel News
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
博客园 - 叶小钗
博客园_首页
V
Visual Studio Blog
宝玉的分享
宝玉的分享
B
Blog
MyScale Blog
MyScale Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
V
V2EX

博客园 - 无名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.