c# - Dependency Injection non interface constructor -
i using unity , wanting following: basicly want pass value type base of operations constructor.
here typical interfacel
public interface irepo { void test(); }
here implemented class, want able inject non interface constructor. possible?
public class repo : baserepo, irepo { public repo(iother other, string username) : base(username) {} public void test(){} }
here unityconfig:
container.registertype<irepo, repo>(); container.registertype<iother , other>();
ive tried this, says repo doesn't have parameter takes string. have ideas?
container.registertype<irepo, repo>("user", new injectionconstructor("user"));
if you're providing injectionconstructor
supply arguments constructor, need supply them all, if registered interfaces themselves.
container.registertype<irepo, repo>("user", new injectionconstructor( container.resolve<iother>(), "user" ));
c# dependency-injection
No comments:
Post a Comment