I just changed from Ninject to TinyIoC for dependency injection, and I'm having trouble introducing the constructor.
I managed to simplify it to this snippet:
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()); } }
which throws a TinyIoCResolutionException:
"Unable to resolve type: TinyIoCTestApp.Foo"
and inside this exception there is a chain of internal exceptions:
"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"
Is there something wrong with how I use constructor injection? I understand that I can call
container.Register<IBar, Bar>(new Bar(value));
and it really works, however the result is a global instance of Bar, which is not what I need.
Any ideas?
source share