コード例 #1
0
        public void InitializeContainer(IApplicationContext context, PredefinedService[] predefinedServices)
        {
            ((DefaultKernel)Kernel).ComponentModelBuilder = new ComponentModelBuilder(Kernel);

            Kernel.ReleasePolicy = new ExplicitReleasePolicy();


            Connect(RuntimeConstants.MiniKernelId, this, typeof(IKernel));

            Connect("kernel", Kernel, typeof(IKernel));
            Connect("windsorContainer", this, typeof(IWindsorContainer));

            //AddCustomComponents(context);
            Kernel.AddComponentInstance(RuntimeConstants.RuntimeConfigurationId, typeof(IApplicationContext), context);


            if (KernelLogger.IsDebugEnabled)
            {
                new KernelLogger(Kernel);
            }

            Kernel.AddComponentInstance(RuntimeConstants.ProductId, typeof(IApplicationContext), context);


            //AddCustomFacilities();
            AddFacility(ComponentIdAwareFacilityId,
                        new TypeAwareFacility(ComponentIdAwareConcern.ComponentIdAwareModelPropertyName, typeof(IComponentIdAware),
                                              ComponentIdAwareConcern.Instance));
            AddFacility(ServiceRunnerFacility.ComponentTypeId, new ServiceRunnerFacility());
            AddFacility(ComponentFacility.ComponentTypeId, new ComponentFacility());


            if (null != context.Arguments)
            {
                Connect(RuntimeConstants.ParsedCommandLineArgumentsId, context.Arguments, typeof(ICommandLineArguments));
            }



            _logger.Debug(" + 开始添加预定义的服务...");

            foreach (PredefinedService svc in predefinedServices)
            {
                Kernel.AddComponent(svc.Id, svc.Service, svc.Implementation);
            }

            _logger.Debug(" > 添加预定义的服务完成.");


            //_initializing = false;
            //_initialized = true;
        }
コード例 #2
0
ファイル: Platform.cs プロジェクト: hotthink/jingxian-project
        public static int Launch(IApplicationContext context, ICommandLineArguments arguments)
        {
            int exitCode = 1;

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            Enforce.ArgumentNotNull <IApplicationContext>(context, "context");
            Enforce.ArgumentNotNullOrEmpty(context.ApplicationLaunchableId, "context.ApplicationLaunchableId");

            _logger.Debug("开始启动...");

            try
            {
                using (KernelAdapter containerAdapter = new KernelAdapter())
                {
                    containerAdapter.Connect(typeof(IApplicationContext), context);
                    containerAdapter.Connect(RuntimeConstants.AssemblyLoaderServiceId
                                             , typeof(IAssemblyLoaderService)
                                             , typeof(AssemblyLoaderService));
                    containerAdapter.Connect(RuntimeConstants.BundleServiceId
                                             , typeof(IBundleService)
                                             , typeof(BundleService));
                    containerAdapter.Connect(RuntimeConstants.ExtensionRegistryId
                                             , typeof(IExtensionRegistry)
                                             , typeof(ExtensionRegistry));
                    containerAdapter.Start();

                    IExtensionRegistry registry = containerAdapter.Get <IExtensionRegistry>();
                    IObjectBuilder     builder  = containerAdapter.Get <IObjectBuilder>();

                    using (IDisposable scope = containerAdapter.Lock())
                    {
                        IExtension[] extensions = registry.GetExtensions(Constants.Points.Services);
                        foreach (IExtension extension in extensions)
                        {
                            containerAdapter.Connect(extension.Id
                                                     , getServiceTypes(builder, extension)
                                                     , builder.GetType(extension.Implementation));
                        }

                        List <object> services = new List <object>();
                        foreach (IExtension extension in extensions)
                        {
                            services.Add(containerAdapter.GetService(extension.Id));
                        }

                        foreach (object instance in services)
                        {
                            MicroKernel.Start(instance, containerAdapter);
                        }
                    }

                    IApplicationLaunchable launchable = BuildApplicationLaunchable(context, registry);
                    exitCode = launchable.Launch(context);

                    containerAdapter.Stop();
                }
            }
            finally
            {
                const string exitMsg = "退出代码 {0}.";
                _logger.InfoFormat(exitMsg, exitCode);
                AppDomain.CurrentDomain.UnhandledException -= OnUnhandledException;
            }
            return(exitCode);
        }