c# - The battle between TDD/Injection and information hiding - A possible compromise? -


i proposed following pattern else. have used few times, when wanted ability inject dependencies test, but still wanted backdoor (somewhat) invisible outsiders. hence, empty public ctor , internal ctor argument:

public class classthatuseinjection {     private readonly someclass _injectedclass;      public classthatuseinjection(): this(new someclass()) {}      internal classthatuseinjection(someclass injectedclass)     {         _injectedclass = injectedclass;     } }   public class someclass {     public object someproperty { get; set; } } 

my idea since empty ctor nothing forward new instance, crime not bad. think? is smelly?

regards, morten

i think ok. in fact, doing injecting class dependency injection , practical use of open/closed principle.
don't see no harm in making internal ctor public one.
problem always, don't want force others create instance of injected class, therefore, default ctor. if want create instance, can go ahead , so.

on related note: imho, should use interface instead of class, otherwise, don't see advantage in passing class in first place...


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -