依赖注入 – StructureMap拦截器
发布时间:2020-12-13 20:47:07 所属栏目:百科 来源:网络整理
导读:我有一堆实现各种接口的服务.例如,IAlbumService,IMediaService等. 我想在这些接口上记录对每个方法的调用.如何使用StructureMap执行此操作? 我意识到这与question几乎相同,只是因为我没有使用windsor. 我想你正在寻找 this answer. static void Main(){ Ob
我有一堆实现各种接口的服务.例如,IAlbumService,IMediaService等.
我想在这些接口上记录对每个方法的调用.如何使用StructureMap执行此操作? 我意识到这与question几乎相同,只是因为我没有使用windsor.
我想你正在寻找
this answer.
static void Main() { ObjectFactory.Configure(x => { x.For<Form>().Use<Form1>() .InterceptWith(new ActivatorInterceptor<Form1>(y => Form1Interceptor(y),"Test")); }); Application.Run(ObjectFactory.GetInstance<Form>()); } public static void Form1Interceptor(Form f) { //Sets the title of the form window to "Testing" f.Text = "Testing"; } 我不会在实际应用程序中使用ObjectFactory,但至少有这个概念. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |