【发布时间】:2020-02-04 12:44:24
【问题描述】:
我当前的 GeneralBindings : Ninject 模块
public class GeneralBindings : NinjectModule
{
public override void Load()
{
// Requires Ninject.Extensions.Conventions
// This binds all interfaces to concretes of the same name eg IClass -> Class.
Kernel.Bind(x => x.FromAssembliesMatching("Company.Project.Scm*")
.SelectAllClasses()
.Excluding(typeof(AffectedCables),
typeof(ApplicationConfigurations),
typeof(ApplicationErrors),
typeof(ApplicationLogEvents),
typeof(AppUsers),
typeof(AppUsersContract),
typeof(Areas)
// etc..
)
.BindAllInterfaces());
然后
Bind<IAffectedCables>().To<AffectedCables>()
.InSingletonScope()
.WithConstructorArgument("url", @"api/AffectedCables");
Bind<IApplicationErrors>().To<ApplicationErrors>()
.InSingletonScope()
.WithConstructorArgument("url", @"api/AppErrors");
Bind<IApplicationConfigurations>().To<ApplicationConfigurations>()
.InSingletonScope()
.WithConstructorArgument("url", @"api/AppConfigurations");
Bind<IApplicationLogEvents>().To<ApplicationLogEvents>()
.InSingletonScope()
.WithConstructorArgument("url", @"api/AppEventLogs");
Bind<IAppUsers>().To<AppUsers>()
.InSingletonScope()
.WithConstructorArgument("url", @"api/AppUsers");
Bind<IAppUsersContract>().To<AppUsersContract>()
.InSingletonScope()
.WithConstructorArgument("url", @"api/AppUserContract");
Bind<IAreas>().To<Areas>()
.InSingletonScope()
.WithConstructorArgument("url", @"api/Areas");
// Etc...
...
谁能建议如何更好地做到这一点?我确信有人可以创建一行代码来保存我目前必须执行的复制和粘贴。
【问题讨论】:
标签: ninject ninject-extensions