将Ninject DI转换为Unity DI

时间:2014-09-10 18:19:08

标签: dependency-injection ninject inversion-of-control unity-container membershipreboot

如何将以下Ninject DI转换为Unity?我无法理解正确的语法。

/// <summary>
    /// Load your modules or register your services here!
    /// </summary>
    /// <param name="kernel">The kernel.</param>
    private static void RegisterServices(IKernel kernel)
    {
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<DefaultMembershipRebootDatabase, BrockAllen.MembershipReboot.Ef.Migrations.Configuration>());

        var config = MembershipRebootConfig.Create();
        kernel.Bind<MembershipRebootConfiguration>().ToConstant(config);
        kernel.Bind<UserAccountService>().ToSelf();
        kernel.Bind<AuthenticationService>().To<SamAuthenticationService>();
        kernel.Bind<IUserAccountQuery>().To<DefaultUserAccountRepository>().InRequestScope();
        kernel.Bind<IUserAccountRepository>().To<DefaultUserAccountRepository>().InRequestScope();
    }

1 个答案:

答案 0 :(得分:1)

  • 使用RegisterInstance方法注册单个实例。
  • 将类型注册为&#39; self&#39;使用RegisterType<T>()方法完成。
  • 使用HierarchicalLifetimeManager
  • 注册具有请求生活方式的类型