Skip to content

Named bindings by convention #36

@Micha-kun

Description

@Micha-kun

I have a lot of implementations that would be good if all their bindings were named dynamically, pe. marking a class with a special attribute with the named instance. Currently, Named method only accepts string as a parameter, not a function like others that could use IContext. Is there a way to do what I'm trying to do currently with Ninject? Thank you.

this.Bind(
                ctx =>
                {
                    ctx.FromThisAssembly()
                       .SelectAllClasses()
                       .InheritedFrom<IReportGenerationManager>()
                       .WithAttribute<ReportPeriodicityAttribute>(attr => attr.Value == "Monthly")
                       .BindToSelf()
                       .Configure(
                            syntax => 
                                syntax
                                  .Named(/* I WANT HERE TO READ THE CLASS ATTRIBUTE TO NAME THE BINDING */)
                                  .WithConstructorArgument(
                                     "dataMartRepository",
                                      ctxArg => ctxArg.Kernel.Get<IDataMartRepository>("Monthly")));
                });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions