C# 依赖注入非接口构造函数

C# 依赖注入非接口构造函数,c#,dependency-injection,C#,Dependency Injection,我正在使用Unity,并希望执行以下操作:我基本上希望将值类型传递到基构造函数中 这是一个典型的界面 public interface Irepo { void test(); } 这是实现的类,我希望能够将非接口注入构造函数。这可能吗 public class Repo : baseRepo, Irepo { public Repo(IOther other, string username) : base(username) {} public void test(){} } 以下是U

我正在使用Unity,并希望执行以下操作:我基本上希望将值类型传递到基构造函数中

这是一个典型的界面

public interface Irepo
{

void test();
}
这是实现的类,我希望能够将非接口注入构造函数。这可能吗

public class Repo : baseRepo, Irepo
{
public Repo(IOther other, string username) : base(username)
{}
public void test(){}
}
以下是UnityConfiguration:

container.RegisterType<Irepo, Repo>();
container.RegisterType<IOther , Other>();
container.RegisterType();
container.RegisterType();
我试过了,但它说Repo没有一个参数可以接受字符串。有人有什么想法吗

container.RegisterType<Irepo, Repo>("user", new InjectionConstructor("user"));
container.RegisterType(“用户”,新注入构造函数(“用户”);

如果您提供了一个
注入构造函数
来为构造函数提供参数,那么您需要提供所有参数,即使它们本身是注册接口

container.RegisterType<Irepo, Repo>("user", new InjectionConstructor(
    container.Resolve<IOther>(),
    "user"
));
container.RegisterType(“用户”,新注入构造函数(
container.Resolve(),
“用户”
));