How to use Func in built-in dependency injection

前端 未结 6 695
梦毁少年i
梦毁少年i 2021-02-14 11:17

Using asp.net 5 I\'d like my controller to be injected with a Funcinstead of T

For example:



        
6条回答
  •  悲哀的现实
    2021-02-14 11:45

    Func does not get registered or resolved by default but there is nothing stopping you from registering it yourself.

    e.g.

    services.AddSingleton(provider => 
      new Func(() => provider.GetService()));
    

    Note that you will also need to register IUnitOfWork itself in the usual way.

提交回复
热议问题