Unity and constructors -
is possible make unity try defined constructors starting 1 arguments down least specific 1 (the default constructor)?
edit
what mean:
foreach (var constructor in concrete.getconstructorsorderbyparametercount()) { if(canfulfildependencies(constructor)) { useconstructor(constructor); break; } } i don't want unity try constructor parameters. want continue trying until finds suitable constructor. if unity doesn't provide behavior default, possible create extension or able this?
edit 2
i got class 2 constructors:
public class myconcrete : isomeinterface { public myconcrete (idepend1 dep, idepend2 dep2) {} public myconcrete(idepend1 dep) {} } the class exists in library used multiple projects. in project want use second constructor. unity stops since can't fulfill dependencies first constructor. , not want change class since first constructor used di in other projects.
hence need unity try resolving constructors.
unity choose constructor parameters unless explicitly tag constructor [injectionconstructor] attribute define constructor unity use.
when state suitable constructor; contingent on environment. if instance want guarantee constructor used when making use of unity use attribute mentioned previously, otherwise explicitly call constructor want use.
what point of unity "trying" constructors? it's purpose provide instance of type in decoupled manner. why iterate through constructors if constructor create instance of type?
edit:
you allow constructor params used within project not have reference type within container making use of child container. not force use of constructor single param allow constructor 2 params work across projects now.
you switch using single constructor across board , force other interface in via form of di (property injection), not constructor injection...therefore base applicable across projects make more sense.
Comments
Post a Comment