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

推荐订阅源

T
Threatpost
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
Engineering at Meta
Engineering at Meta
爱范儿
爱范儿
博客园 - Franky
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
雷峰网
雷峰网
月光博客
月光博客
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
罗磊的独立博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog
Know Your Adversary
Know Your Adversary
宝玉的分享
宝玉的分享
L
Lohrmann on Cybersecurity
S
SegmentFault 最新的问题
L
LangChain Blog
K
Kaspersky official blog
P
Palo Alto Networks Blog
P
Privacy & Cybersecurity Law Blog
美团技术团队
Scott Helme
Scott Helme
B
Blog RSS Feed
T
Threat Research - Cisco Blogs
博客园_首页
L
LINUX DO - 热门话题
腾讯CDC
C
CERT Recently Published Vulnerability Notes
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
V
V2EX
Martin Fowler
Martin Fowler
T
The Exploit Database - CXSecurity.com
人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
Latest news
Latest news
S
Schneier on Security
AWS News Blog
AWS News 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 Configuration
无名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.