如何使Autofac在果园CMS执行财产注入 [英] How to make Autofac perform property injection in Orchard CMS

查看:181
本文介绍了如何使Autofac在果园CMS执行财产注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能做财产注射用OrchardCMS?

Is it possible to do property injection with the OrchardCMS?

我知道,果园使用Autofac和Autofac不会做财产注入,但我需要知道如何做物业注入了IOrchardServices接口。

I know that Orchard uses Autofac and that Autofac does do property injection, but I need to know how to do property injection for the IOrchardServices interface.

我们的团队正在乌节但我们的code基地都在ASP.NET 4.0 WebForms和因此我们将继续为ASPX页面,慢慢地迁移这些网页说成果园随着时间的许可证。

Our team is looking at Orchard but our code base is all in ASP.NET 4.0 WebForms and so we will continue to serve aspx pages and slowly migrate those said pages into Orchard as time permits.

就这样,我们需要一种方法来OrchardServices对象获取访问权限。我在想,这是我不得不拿出我自己。 没有任何一个有乌节执行财产注入任何好的例子吗?

With that, we'll need a way to get access to the OrchardServices object. I'm thinking that this is something I'd have to come up on my own. Does any one have any good examples of performing property injection in Orchard?

推荐答案

这是pretty简单 - 看看源它是如何与 ILogger 接口来完成,做同为 IOrchardServices 。源文件的 Orchard.Framework /日志/ LoggingModule.cs 。这正是你在找什么,我猜。结果
一切都正在通过Autofac模块(实施 Autofac.Module 类)来完成。什么是类所做的是:

It's pretty simple - look into the source how it's done with ILogger interfaces and do the same for IOrchardServices. The source file is Orchard.Framework/Logging/LoggingModule.cs. It's exactly what you are looking for, I guess.
Everything is being done via Autofac module (implementation of Autofac.Module class). What that class does is to:


  • 注册的 ILogger 接口(加载法)和
  • 实施
  • 得到处理的对象的属性,并设置适当的人来对象从容器( AttachToComponentRegistration 法)解决了。

  • register the implementation of ILogger interfaces (Load method) and
  • get properties of the processed object and set appropriate ones to object resolved from the container (AttachToComponentRegistration method).

pretty简单。 Autofac模块,插入到DI过程中一个很好的方式。

Pretty simple. Autofac modules are a nice way to plug into the DI process.

这将是不够的只是该源文件复制到您的自定义果园模块和不断变化的 ILogger IOrchardServices (,当然注册类)。我提到的类利用工厂模式来创建实例,但你可以通过并摆脱工厂有关的东西。

It would be enough just to copy that source file to your custom Orchard module and changing ILogger to IOrchardServices (and, of course the registered class). The class I mentioned makes use of factory pattern to create instances, but you can change that to simple object creation via new and get rid of the factory-related things.

这篇关于如何使Autofac在果园CMS执行财产注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆