How can I pass in constructor arguments when I register a type in Unity?

后端 未结 2 1249
别跟我提以往
别跟我提以往 2021-02-19 17:46

I have the following type being registered in Unity:

container.RegisterType, AzureTable>();

The

2条回答
  •  生来不讨喜
    2021-02-19 18:33

    You could give this a try:

    // Register your type:
    container.RegisterType), typeof(AzureTable)>()
    
    // Then you can configure the constructor injection (also works for properties):
    container.Configure()
      .ConfigureInjectionFor>(
        new InjectionConstructor(myConstructorParam1, "my constructor parameter 2") // etc.
      );
    

    More info from MSDN here.

提交回复
热议问题