依存性注入のためにNinjectからTinyIoCに変更したばかりで、コンストラクター注入に問題があります。
私はそれをこのスニペットまで単純化することができました:
public interface IBar { }
public class Foo
{
public Foo(IBar bar) { }
}
public class Bar : IBar
{
public Bar(string value) { }
}
class Program
{
static void Main(string[] args)
{
var container = TinyIoCContainer.Current;
string value = "test";
container.Register<IBar, Bar>().UsingConstructor(() => new Bar(value));
var foo = container.Resolve<Foo>();
Console.WriteLine(foo.GetType());
}
}
これにより、TinyIoCResolutionExceptionが次のようにスローされます。
"Unable to resolve type: TinyIoCTestApp.Foo"
その例外の中には、一連の内部例外があります。
"Unable to resolve type: TinyIoCTestApp.Bar"
"Unable to resolve type: System.String"
"Unable to resolve type: System.Char[]"
"Value cannot be null.\r\nParameter name: key"
コンストラクターインジェクションの使用方法に何か問題がありますか?私は私が呼ぶことができることに気づきます
container.Register<IBar, Bar>(new Bar(value));
それは確かに機能しますが、結果はBarのグローバルインスタンスであり、私が求めているものではありません。
何か案は?