Exemplo n.º 1
0
        public void AutoModuleRegistersSelfBindingForTypesWithServiceAttribute()
        {
            AutoModule module = new AutoModule(Assembly.GetExecutingAssembly());

            using (var kernel = new StandardKernel(module))
            {
                ICollection <IBinding> bindings = kernel.Components.BindingRegistry.GetBindings(typeof(ObjectWithSelfBindingServiceAttribute));
                Assert.That(bindings, Is.Not.Null);
                Assert.That(bindings, Is.Not.Empty);

                var mock = kernel.Get <ObjectWithSelfBindingServiceAttribute>();
                Assert.That(mock, Is.Not.Null);
            }
        }
Exemplo n.º 2
0
        public void AutoModuleRegistersProviderBindingForTypesWithServiceAttribute()
        {
            var module = new AutoModule(Assembly.GetExecutingAssembly());

            using (var kernel = new StandardKernel(module))
            {
                Type type = typeof(ObjectWithProviderBindingServiceAttribute);

                IContext context = kernel.Components.ContextFactory.Create(type);
                IBinding binding = kernel.Components.BindingSelector.SelectBinding(type, context);

                Assert.That(binding, Is.Not.Null);
                Assert.That(binding.Provider, Is.InstanceOfType(typeof(ServiceAttributeObjectProvider)));

                var mock = kernel.Get <ObjectWithProviderBindingServiceAttribute>();
                Assert.That(mock, Is.Not.Null);
            }
        }