Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    public static Api CreateApi(int condition)
    {
        Api api = null;

        if (condition == 1)
        {
            api = new ImplA();
        }
        else
        {
            api = new ImplB();
        }
        return(api);
    }
Ejemplo n.º 4
0
        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"));
            }
        }
Ejemplo n.º 5
0
        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"));
            }
        }
Ejemplo n.º 6
0
        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"));
            }
        }
Ejemplo n.º 7
0
 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"));
			}
		}