小编Mat*_*ias的帖子

我可以在Orchard CMS中使用我的Ninject .NET项目吗?

我正在使用Orchard CMS创建一个网站,我有一个用Ninject编写的外部.NET项目用于依赖注入,我想与Orchard CMS中的模块一起使用.我知道Orchard使用Autofac进行依赖注入,这引起了我的问题,因为我之前从未使用过DI.

我创建了一个Autofac模块,UserModule它注册了一个源代码UserRegistrationSource,如下所示:

UserModule.cs

public class UserModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.RegisterSource(new UserRegistrationSource());
    }
}
Run Code Online (Sandbox Code Playgroud)

UserRegistrationSource.cs

public class UserRegistrationSource : IRegistrationSource
{
    public bool IsAdapterForIndividualComponents
    {
        get { return false; }
    }

    public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Func<Service, IEnumerable<IComponentRegistration>> registrationAccessor)
    {
        var serviceWithType = service as IServiceWithType;
        if (serviceWithType == null)
            yield break;

        var serviceType = serviceWithType.ServiceType;
        if (!serviceType.IsInterface || !typeof(IUserServices).IsAssignableFrom(serviceType) || serviceType != typeof(IUserServices))
            yield break;

        var registrationBuilder = // …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc ninject autofac orchardcms

5
推荐指数
1
解决办法
536
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

autofac ×1

ninject ×1

orchardcms ×1