Exemple #1
0
        private static Container ConfigureContainer()
        {
            var registry = new StructureMap.Registry();

            registry.IncludeRegistry <RulesRegistry>();
            registry.IncludeRegistry <ImportRegistry>();
            registry.IncludeRegistry <DefaultRegistry>();
            var container = new Container(registry);

            return(container);
        }
        private void GetStructureMapConfig(ConfigurationExpression cfg)
        {
            cfg.For <IWindowManager>().Use <WindowManager>().Singleton();
            cfg.For <IEventAggregator>().Use <EventAggregator>().Singleton();
            cfg.For <ILogger>().Singleton().Use <Logger>();


            var exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (exeDir != null)
            {
                var modDir = Path.Combine(exeDir, "Modules");

                var registry = new Registry();


                #region MediatR registry

                // ------- START MediatR Configure -----------------------

                // INFO: Пока в этом сканере нет необходимости

                /*
                 * // используем внешний mediator pattern
                 * registry.Scan(scanner =>
                 * {
                 *  scanner.TheCallingAssembly();
                 *  //scanner.Assembly(this.GetType().Assembly); // ?
                 *  scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<>)); // Handlers with no response
                 *  scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>)); // Handlers with a response
                 *  scanner.ConnectImplementationsToTypesClosing(typeof(IAsyncRequestHandler<>)); // Async handlers with no response
                 *  scanner.ConnectImplementationsToTypesClosing(typeof(IAsyncRequestHandler<,>)); // Async Handlers with a response
                 *  scanner.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
                 *  scanner.ConnectImplementationsToTypesClosing(typeof(IAsyncNotificationHandler<>));
                 * });
                 */

                // Scan other assembly modules Regisry Types with DLL like name *Extension.dll
                registry.Scan(scanner =>
                {
                    if (Directory.Exists(modDir))
                    {
                        //  More examples Scan:
                        // https://github.com/structuremap/structuremap/blob/master/src/StructureMap.Testing/Examples.cs
                        scanner.AssembliesFromPath(modDir, assembly => assembly.GetName().Name.Contains("Extension"));
                    }

                    scanner.WithDefaultConventions();
                    // Если есть, автоматичесски запускать регистрацию классов производных от Registry
                    scanner.LookForRegistries();
                    //canner.Convention<ViewRegistrationConvention>();
                });

                //registry.For<SingleInstanceFactory>().Use<SingleInstanceFactory>(ctx => t => ctx.GetInstance(t));
                //registry.For<MultiInstanceFactory>().Use<MultiInstanceFactory>(ctx => t => ctx.GetAllInstances(t));
                //registry.For<IMediator>().Use<Mediator>();

                // ------- END MediatR Configure -----------------------

                #endregion

                registry.IncludeRegistry <SheduleConfigRegistry>();
                registry.IncludeRegistry <SystemTrayIconRegistry>();

                cfg.AddRegistry(registry);
            }
        }