My Current GeneralBindings : Ninject Module
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());
then
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...
...
Can anyone suggest how to do this better? I'm sure that someone can create a single line of code that will save the copy and pasting that I have to perform at the moment.
A blind shot, not tested, but I would try with an attribute
then
where
BindingGeneratoris :usage would then be :