Ninject - binding constructors with arguments / Entity Framework connection string

后端 未结 2 1776
天涯浪人
天涯浪人 2021-02-18 16:28

Please forgive my ignorance, but I am very new to IOC and NinJect. I have searched for high and low for easily understandable solutions but so far they have eluded me.

S

2条回答
  •  眼角桃花
    2021-02-18 17:16

    You can use the .WithConstructorArgument() method to specify constructor arguments. The first argument should be the name of the constructor parameter.

    public class StandardModule : NinjectModule
    {
        public override void Load()
        {
            string connectionString = "...";
            Bind()
                .WithConstructorArgument("sqlConnectionString", connectionString);
        }
    

    }

提交回复
热议问题