예제 #1
0
        public void RegisterDependencies()
        {
            IUnityContainer container = new UnityContainer();

            MockStartupController controller = new MockStartupController(container);
            controller.CallRegisterDependencies();

            Assert.That(container.IsRegistered<IStartupView>(), Is.True);
            Assert.That(container.IsRegistered<IMainView>(), Is.True);
        }
예제 #2
0
        static MessageService()
        {
            if (!MessagingEnabled) return;

            var unitySection = ConfigurationManager.GetSection("unity");
            if (unitySection == null)
            {
                log.Error("Required unity configuration for Message Sender");
                return;
            }

            try
            {
                var unity = new UnityContainer().LoadConfiguration(unityContainerName);
                if (unity.IsRegistered<IMessageSender>())
                {
                    sender = unity.Resolve<IMessageSender>();
                }
                else
                {
                    log.Error("Required unity configuration for Message Sender");
                }
            }
            catch(Exception ex)
            {
                log.Error("Error while resolving Message Sender: " + ex);
            }
        }
        public void Boostrap_UrlServiceIsRegistered()
        {
            IUnityContainer container = new UnityContainer();
            WhippedCreamDataLayer.Bootstrap(container, new System.Uri("http://www.google.com"));

            Assert.IsTrue(container.IsRegistered<IUrlService>(), @"
            If the user passes in a base uri, then we need to generate the IUrlService for them and make sure
            it is registered in the container.
            ");
        }
        public void Can_scan_folder_and_exclude_assemblies_by_using_a_predicate()
        {
            var container = new UnityContainer();

            container.Configure(x => x.Scan(scan =>
                                            {
                                                scan.AssembliesInDirectory(Environment.CurrentDirectory, a => a.GetName().Name != "UnityConfiguration.Tests");
                                                scan.With<FirstInterfaceConvention>();
                                            }));

            Assert.That(container.IsRegistered<IFooService>(), Is.False);
        }
        public void Does_not_register_when_interface_is_not_found()
        {
            var container = new UnityContainer();

            container.Configure(x => x.Scan(scan =>
            {
                scan.AssemblyContaining<NamedService>();

                scan.WithNamingConvention().WithInterfaceName(t => "IDoNotExist");
            }));

            Assert.That(container.IsRegistered<INamedService>(), Is.False);
        }
        private void AssertServicesAreRegisteredForAllRequests(UnityContainer container)
        {
            var serviceToRequestCorrespondances = ListAllExpectedServiceTypesForAllRequests();

            var notRegisteredServices =
                serviceToRequestCorrespondances.Where(kvp => !container.IsRegistered(kvp.Key)).ToList();

            if(notRegisteredServices.Any())
            {
                var message = notRegisteredServices.Count +
                    " Executable services are not registered for some Requests and will cause the application to fail when looking up the service for the request: \n" +
                              String.Join("\n", notRegisteredServices.Select(kvp => String.Format("- {0} (for Request {1})", kvp.Key, kvp.Value)));
                Assert.Fail(message);
            }
        }
예제 #7
0
파일: Program.cs 프로젝트: jbogard/MediatR
        private static IMediator BuildMediator()
        {
            var container = new UnityContainer();
            container.RegisterType<IMediator, Mediator>();
            container.RegisterTypes(AllClasses.FromAssemblies(typeof(Ping).Assembly), WithMappings.FromAllInterfaces, GetName, GetLifetimeManager);
            container.RegisterType(typeof(INotificationHandler<>), typeof(GenericHandler), GetName(typeof(GenericHandler)));
            container.RegisterType(typeof(IAsyncNotificationHandler<>), typeof(GenericAsyncHandler), GetName(typeof(GenericAsyncHandler)));
            container.RegisterInstance(Console.Out);
            container.RegisterInstance<SingleInstanceFactory>(t => container.IsRegistered(t) ? container.Resolve(t) : null);
            container.RegisterInstance<MultiInstanceFactory>(t => container.ResolveAll(t));

            var mediator = container.Resolve<IMediator>();

            return mediator;
        }
예제 #8
0
        static void Main(string[] args)
        {
            var container = new UnityContainer().LoadConfiguration();
            if (container.IsRegistered<ILogger>())
            {
                var ilogger = container.Resolve<ILogger>();
                ilogger.Log("TEst");
            }

            //container.AddNewExtension<Interception>();
            //container.RegisterType<IApplication, Application>(
            //    new InterceptionBehavior<PolicyInjectionBehavior>(),
            //    new Interceptor<InterfaceInterceptor>()
            //   // new InterceptionBehavior<LoggingInterceptionBehavior>()
            //    );

            //var app = container.Resolve<IApplication>();
            //app.Run();

            //new Test().LongRunningCalc();
            Console.ReadKey(false);
        }
예제 #9
0
        private static void ConfigureCoreContextByUnity(object section)
        {
            ConfigureCoreContextByDefault();

            if (((UnityConfigurationSection)section).Containers["Core"] != null)
            {
                var unity = new UnityContainer().LoadConfiguration("Core");
                if (unity.IsRegistered<IConfigurationClient>())
                {
                    Configuration = unity.Resolve<IConfigurationClient>();
                }
                if (unity.IsRegistered<ITenantManagerClient>())
                {
                    TenantManager = unity.Resolve<ITenantManagerClient>();
                }
                if (unity.IsRegistered<IUserManagerClient>())
                {
                    UserManager = unity.Resolve<IUserManagerClient>();
                }
                if (unity.IsRegistered<IGroupManagerClient>())
                {
                    GroupManager = unity.Resolve<IGroupManagerClient>();
                }
                if (unity.IsRegistered<IAuthManagerClient>())
                {
                    Authentication = unity.Resolve<IAuthManagerClient>();
                }
                if (unity.IsRegistered<IAzManagerClient>())
                {
                    AuthorizationManager = unity.Resolve<IAzManagerClient>();
                }
                if (unity.IsRegistered<ISubscriptionManagerClient>())
                {
                    SubscriptionManager = unity.Resolve<ISubscriptionManagerClient>();
                }
            }
        }
        public void Bootstrap_ServicesRegistered(System.Type targetType)
        {
            IUnityContainer container = new UnityContainer();
            WhippedCreamDataLayer.Bootstrap(container, new System.Uri("http://www.google.com"));

            Assert.IsTrue(container.IsRegistered(targetType), "The type ({0}) was not registered when it was expected to be.", targetType);
        }
 private void AssertServiceForRequestIsRegistered(UnityContainer container, Type requestType)
 {
     var serviceTypeToFind = GetExpectedServiceTypeForRequest(requestType);
     Assert.IsTrue(container.IsRegistered(serviceTypeToFind), string.Format("Type {0} should be registered", serviceTypeToFind));
 }
예제 #12
0
        public void RegisterInstance_Valid()
        {
            var helper = new UnityHelper();
            var instance = new TestClass1() { Name = "test" };

            var container = new UnityContainer();
            Assert.IsFalse(container.IsRegistered(typeof(ITestInterface)));

            helper.RegisterInstance(container, typeof(ITestInterface), instance);
            Assert.IsTrue(container.IsRegistered(typeof(ITestInterface)));
            Assert.AreEqual(instance, container.Resolve<ITestInterface>());
        }
예제 #13
0
        public void RegisterType_Valid()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            Assert.IsFalse(container.IsRegistered(typeof(ITestInterface)));

            helper.RegisterType(container, typeof(ITestInterface), typeof(TestClass1), RegistrationType.Singleton);
            Assert.IsTrue(container.IsRegistered(typeof(ITestInterface)));
        }
예제 #14
0
 public void IsRegistered(System.Type targetType)
 {
     IUnityContainer container = new UnityContainer();
     Bootstrapper.Bootstrap(container);
     Assert.IsTrue(container.IsRegistered(targetType));
 }
예제 #15
0
 private static void ConfigureCoreContextByUnity(object section)
 {
     if (((UnityConfigurationSection)section).Containers["Core"] != null)
     {
         var unity = new UnityContainer().LoadConfiguration("Core");
         if (unity.IsRegistered<CoreConfiguration>())
         {
             Configuration = unity.Resolve<CoreConfiguration>();
         }
         if (unity.IsRegistered<TenantManager>())
         {
             TenantManager = unity.Resolve<TenantManager>();
         }
         if (unity.IsRegistered<UserManager>())
         {
             UserManager = unity.Resolve<UserManager>();
         }
         if (unity.IsRegistered<AuthManager>())
         {
             Authentication = unity.Resolve<AuthManager>();
         }
         if (unity.IsRegistered<AuthorizationManager>())
         {
             AuthorizationManager = unity.Resolve<AuthorizationManager>();
         }
         if (unity.IsRegistered<SubscriptionManager>())
         {
             SubscriptionManager = unity.Resolve<SubscriptionManager>();
         }
     }
 }