Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named bindings by convention #36

Open
Micha-kun opened this issue Oct 13, 2020 · 0 comments
Open

Named bindings by convention #36

Micha-kun opened this issue Oct 13, 2020 · 0 comments

Comments

@Micha-kun
Copy link

Micha-kun commented Oct 13, 2020

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")));
                });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant