将 ninject membershipreboot 转换为 Autofac
Convert ninject membershipreboot to Autofac
我正在玩会员重新启动提供程序,并找到了代码示例,但使用 Ninject 而不是 Autofac。
有人可以帮我把 Ninject 的东西转换成 Autofac:
kernel.Bind<MembershipRebootConfiguration<CustomUserAccount>>().ToConstant(config);
kernel.Bind<IUserAccountRepository<CustomUserAccount>>().To<CustomRepository>()
.InRequestScope();
kernel.Bind<CustomDatabase>().ToSelf().InRequestScope();
kernel.Bind<IUserAccountQuery>().To<CustomRepository>().InRequestScope();
kernel.Bind<AuthenticationService<CustomUserAccount>>()
.To<SamAuthenticationService<CustomUserAccount>>();
我只知道修改其中一个
var builder = new ContainerBuilder();
builder.RegisterType<CustomRepository>().As<IUserAccountQuery>()
.InstancePerLifetimeScope();
一旦我开始工作,我会把它提交给在 MRB 上工作的人,也许可以帮助其他人。
根据 Autofac 文档,我会这样翻译:
var builder = new ContainerBuilder();
builder.RegisterInstance(config)
.As<MembershipRebootConfiguration<CustomUserAccount>>();
builder.RegisterType<CustomRepository>()
.As<IUserAccountRepository<CustomUserAccount>>()
.InstancePerRequest();
builder.RegisterType<CustomDatabase>()
.AsSelf()
.InstancePerRequest();
builder.RegisterType<CustomRepository>()
.As<IUserAccountQuery>()
.InstancePerRequest();
builder.RegisterType<SamAuthenticationService<CustomUserAccount>>()
.As<AuthenticationService<CustomUserAccount>>();
请注意,我使用了 InstancePerRequest()
,这可能需要您为您正在使用的 ASP.NET 版本添加相应的 NuGet 包(使用 [=12= 时 Ninject 也是如此]).
我正在玩会员重新启动提供程序,并找到了代码示例,但使用 Ninject 而不是 Autofac。
有人可以帮我把 Ninject 的东西转换成 Autofac:
kernel.Bind<MembershipRebootConfiguration<CustomUserAccount>>().ToConstant(config);
kernel.Bind<IUserAccountRepository<CustomUserAccount>>().To<CustomRepository>()
.InRequestScope();
kernel.Bind<CustomDatabase>().ToSelf().InRequestScope();
kernel.Bind<IUserAccountQuery>().To<CustomRepository>().InRequestScope();
kernel.Bind<AuthenticationService<CustomUserAccount>>()
.To<SamAuthenticationService<CustomUserAccount>>();
我只知道修改其中一个
var builder = new ContainerBuilder();
builder.RegisterType<CustomRepository>().As<IUserAccountQuery>()
.InstancePerLifetimeScope();
一旦我开始工作,我会把它提交给在 MRB 上工作的人,也许可以帮助其他人。
根据 Autofac 文档,我会这样翻译:
var builder = new ContainerBuilder();
builder.RegisterInstance(config)
.As<MembershipRebootConfiguration<CustomUserAccount>>();
builder.RegisterType<CustomRepository>()
.As<IUserAccountRepository<CustomUserAccount>>()
.InstancePerRequest();
builder.RegisterType<CustomDatabase>()
.AsSelf()
.InstancePerRequest();
builder.RegisterType<CustomRepository>()
.As<IUserAccountQuery>()
.InstancePerRequest();
builder.RegisterType<SamAuthenticationService<CustomUserAccount>>()
.As<AuthenticationService<CustomUserAccount>>();
请注意,我使用了 InstancePerRequest()
,这可能需要您为您正在使用的 ASP.NET 版本添加相应的 NuGet 包(使用 [=12= 时 Ninject 也是如此]).