Skip to content

I dont' understand have functions with arguments works #57

Answered by NikolayPianikov
ekalchev asked this question in Q&A
Discussion options

You must be logged in to vote
DI.Setup(nameof(Composition))
    .Bind<IClock>().As(Lifetime.Singleton).To<Clock>()
    // Binds a dependency of type int
    // to the source code statement "dependencyId"
    .Bind<int>().To<int>("dependencyId")
    .Bind<Func<int, IDependency>>()
        .To<Func<int, IDependency>>(ctx =>
            dependencyId =>
            {
                // Builds up an instance of type Dependency
                // referring the source code statement "dependencyId"
                ctx.Inject<Dependency>(out var dependency);
                return dependency;
            })
    .Bind<IService>().To<Service>()

    // Composition root
    .Root<IService>("Root");

The key here is .Bind<int>().To…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ekalchev
Comment options

Answer selected by ekalchev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants