Unity constructor injection with other parameter

前端 未结 3 514
悲&欢浪女
悲&欢浪女 2021-01-04 12:37

I have a class with a constructor that looks like the following:

public BatchService(IRepository repository, ILogger logger, string user)

I

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 13:12

    Please don't abuse Unity as a ServiceLocator.

    If you want to create objects that need runtime parameters use a factory. You can even drop the act of implementing that factory by either using the Unity version of Typed Factories or let Unity generate factory delegates for you.

提交回复
热议问题