Arb*_*æde 3 asp.net-mvc sitecore autofac sitecore8
有没有人知道如何设置正确的IoC(Autofac)并将其与Sitecore MVC一起使用?我已经创建了一个特定的Pipeline,但是当sitecore渲染页面(Controller rendering)时,解析不起作用.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<initialize>
<processor type="MyLib.AutofacProcessor, MyLib" />
</initialize>
</pipelines>
</sitecore>
</configuration>
Run Code Online (Sandbox Code Playgroud)
public class AutofacProcessor
{
public void Process(PipelineArgs args)
{
AutofacProcessor.Start();
}
public static void Start()
{
var builder = new ContainerBuilder();
builder.RegisterType<MyService>().As<IMyService>().PropertiesAutowired();
var container = builder.Build();
IDependencyResolver resolver = new AutofacDependencyResolver(container);
DependencyResolver.SetResolver(resolver);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当sitecore调用它时,我在控制器中的属性为null.如何在Sitecore术语中注册?在常规ASP MVC中,它非常简单.
您还需要覆盖Sitecore的默认ControllerFactory.
<processor type="Sitecore.Mvc.Pipelines.Loader.InitializeControllerFactory, Sitecore.Mvc"/>
Run Code Online (Sandbox Code Playgroud)
这是NInject的一个示例,应该很容易修改它以使用AutoFAC执行相同操作:http://blog.istern.dk/2012/10/23/sitecore-mvc-new-ninject-controller-factory-clean-version/
| 归档时间: |
|
| 查看次数: |
781 次 |
| 最近记录: |