Is it bad to use servicelocation instead of constructor injection to avoid writing loads of factory classes

后端 未结 3 1803
离开以前
离开以前 2020-12-09 13:08

Right now we use DI/IOC and when we need to pass extra parameters to a constructor we use a factory class e.g.

public class EmailSender 
{
    internal Email         


        
3条回答
  •  执念已碎
    2020-12-09 13:54

    The largest reason I can think of (without just looking at issues with Service Locators in general) is that it is not what I as a user of your class would expect.

    Meta discussion:
    Some DI frameworks (Guice for example) will build the factory for you.

    Some people advocate separating the "newable" from the "injectable".

提交回复
热议问题