public void test_bind_property() { var registry = new FixedServiceRegistry(); var impl = new ImplA(); registry.Bound[typeof(IDepA)] = impl; var instance = new PropertyBinder(registry); var sample = new SampleClass(); instance.Bind(sample); Assert(sample.instance == impl); }
public static Api CreateApi(int condition) { Api api = null; if (condition == 1) { api = new ImplA(); } else { api = new ImplB(); } return(api); }
public void CanOverrideMultipleConstructorArgumentsViaAnonymouslyTypedObject() { IMock child = new ImplA(); IModule module = new InlineModule( m => m.Bind <HybridInjectionMock>() .ToSelf() .WithConstructorArguments(new { connectionString = "this is a connection string", child = child }) ); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get <HybridInjectionMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock.Child, Is.Not.Null); Assert.That(mock.Child, Is.SameAs(child)); Assert.That(mock.ConnectionString, Is.EqualTo("this is a connection string")); } }
public void BindingParametersOverrideResolutionOfDependencies() { var childMock = new ImplA(); IModule module = new InlineModule( m => m.Bind <HybridInjectionMock>() .ToSelf() .WithConstructorArgument("connectionString", "this is a connection string") .WithConstructorArgument("child", childMock) ); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get <HybridInjectionMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock.Child, Is.Not.Null); Assert.That(mock.Child, Is.SameAs(childMock)); Assert.That(mock.ConnectionString, Is.EqualTo("this is a connection string")); } }
public void CanOverrideMultipleConstructorArgumentsViaDictionary() { var child = new ImplA(); var module = new InlineModule(m => { var arguments = new Dictionary <string, object>(); arguments.Add("connectionString", "this is a connection string"); arguments.Add("child", child); m.Bind <HybridInjectionMock>().ToSelf().WithConstructorArguments(arguments); }); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get <HybridInjectionMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock.Child, Is.Not.Null); Assert.That(mock.Child, Is.SameAs(child)); Assert.That(mock.ConnectionString, Is.EqualTo("this is a connection string")); } }
public DependencyDispatcher(ImplA a, ImplB b) { this.a = a; this.b = b; }
public void CanOverrideMultipleConstructorArgumentsViaDictionary() { var child = new ImplA(); var module = new InlineModule(m => { var arguments = new Dictionary<string, object>(); arguments.Add("connectionString", "this is a connection string"); arguments.Add("child", child); m.Bind<HybridInjectionMock>().ToSelf().WithConstructorArguments(arguments); }); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get<HybridInjectionMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock.Child, Is.Not.Null); Assert.That(mock.Child, Is.SameAs(child)); Assert.That(mock.ConnectionString, Is.EqualTo("this is a connection string")); } }
public void BindingParametersOverrideResolutionOfDependencies() { var childMock = new ImplA(); IModule module = new InlineModule( m => m.Bind<HybridInjectionMock>() .ToSelf() .WithConstructorArgument("connectionString", "this is a connection string") .WithConstructorArgument("child", childMock) ); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get<HybridInjectionMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock.Child, Is.Not.Null); Assert.That(mock.Child, Is.SameAs(childMock)); Assert.That(mock.ConnectionString, Is.EqualTo("this is a connection string")); } }
public void CanOverrideMultipleConstructorArgumentsViaAnonymouslyTypedObject() { IMock child = new ImplA(); IModule module = new InlineModule( m => m.Bind<HybridInjectionMock>() .ToSelf() .WithConstructorArguments(new { connectionString = "this is a connection string", child = child }) ); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get<HybridInjectionMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock.Child, Is.Not.Null); Assert.That(mock.Child, Is.SameAs(child)); Assert.That(mock.ConnectionString, Is.EqualTo("this is a connection string")); } }