IOptions Injection

前端 未结 5 1758
情书的邮戳
情书的邮戳 2020-12-08 19:17

It seems to me that it\'s a bad idea to have a domain service require an instance of IOptions to pass it configuration. Now I\'ve got pull additional (unnecessary?) depend

5条回答
  •  心在旅途
    2020-12-08 19:55

    I can't stand the IOptions recommendation either. It's a crappy design to force this on developers. IOptions should be clearly documented as optional, oh the irony.

    This is what I do for my configuraition values

    var mySettings = new MySettings();
    Configuration.GetSection("Key").Bind(mySettings);
    
    services.AddTransient(p => new MyService(mySettings));
    

    You retain strong typing and don't need need to use IOptions in your services/libraries.

提交回复
热议问题