示例#1
0
        public static void Enable(TinyIoCContainer container, IPipelines pipelines)
        {
            ISchemaHandler handler;
            container.TryResolve(out handler);

            ISchemaConfiguration configuration;
            container.TryResolve(out configuration);

            isEnabled = true;
            schemaProvider = new OmletSchemaProvider(container.Resolve<IRootPathProvider>(), configuration);
            schemaHandler = new OmletSchemaHandler(handler);
        }
示例#2
0
        public object GetService(Type serviceType)
        {
            object resolvedType = null;

            Container.TryResolve(serviceType, out resolvedType);
            return(resolvedType);
        }
示例#3
0
        private TUnit GetSUTInstance()
        {
            if (!alreadyConstructedSUT)
            {
                constructedSUTInstance = ConstructSUT();

                if (constructedSUTInstance == null)
                {
                    throw new InvalidOperationException("Failed to construct SUT: ConstructSUT returned null");
                }

                if (mockingContainer.TryResolve(typeof(TUnit), new ResolveOptions {
                    UnregisteredResolutionAction = UnregisteredResolutionActions.Fail
                }, out var resolvedType))
                {
                    if (!typeof(TUnit).IsValueType && !ReferenceEquals(constructedSUTInstance, resolvedType))
                    {
                        throw new InvalidOperationException("An SUT instance other than the newly constructed instance was resolved from the container");
                    }
                }
                else
                {
                    Set(constructedSUTInstance);
                }

                alreadyConstructedSUT = true;
            }

            return(constructedSUTInstance);
        }
示例#4
0
        public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            IController resolvedType = null;

            Container.TryResolve <IController>(controllerName, out resolvedType);
            return(resolvedType);
        }
        public void GivenUrlModifierTypeIsNotSet_WhenConfigureContainer_ThenContainerCannotResolveIUrlModifier()
        {
            var container = new TinyIoCContainer();

            config.Configure(container);

            object obj;
            container.TryResolve(typeof(IUrlModifier), out obj).ShouldBeFalse();
        }
示例#6
0
        private void CopyServerUrlToClipboard()
        {
            IClipboard clipboard;

            if (_ResourceResolver.TryResolve <IClipboard>(out clipboard))
            {
                clipboard.SetText(Configuration.ServerUrl);
            }
        }
示例#7
0
        public object GetService(Type serviceType)
        {
            object service = null;

            if (!_TinyIoCContainer.CanResolve(serviceType) || !_TinyIoCContainer.TryResolve(serviceType, out service))
            {
                service = null;
            }
            return(service);
        }
示例#8
0
        public void GivenStylesheetMinifierTypeIsNotSet_WhenConfigureContainer_ThenContainerCannotResolveIStylesheetMinfier()
        {
            var container = new TinyIoCContainer();

            config.Configure(container);

            object obj;

            container.TryResolve(typeof(IStylesheetMinifier), out obj).ShouldBeFalse();
        }
示例#9
0
        public object TryResolve(Type serviceType)
        {
            if (!mContainer.TryResolve(serviceType, out object instance))
            {
                instance = null;
            }
            else
            {
                mContainer.BuildUp(instance);
            }

            return(instance);
        }
示例#10
0
        /// <summary>
        /// 输出当前需要注册的模块
        /// </summary>
        private void OutputRegistedModules()
        {
            Task.Factory.StartNew(() =>
            {
                foreach (var item in this.registedModules)
                {
                    WriteToLog($"模块[{item.ModuleType.Name}]加载成功...");

                    if (container != null && container.TryResolve(item.ModuleType, out object module))
                    {
                        var m = (NancyModule)module;
                        foreach (var route in m.Routes)
                        {
                            WriteToLog($"URL:{route.Description.Method} {route.Description.Path}");
                        }
                    }
                }
            }, cancellationToken);
        }
示例#11
0
        /// <summary>
        /// 設定を保存します。
        /// </summary>
        private void SaveConfig(bool force = false)
        {
            Registry registry;

            if (!_container.TryResolve(out registry))
            {
                return;
            }
            if (Config == null || Overlays == null || registry.EventSources == null)
            {
                return;
            }

            try
            {
                foreach (var overlay in this.Overlays)
                {
                    overlay.SavePositionAndSize();
                }

                foreach (var es in registry.EventSources)
                {
                    if (es != null)
                    {
                        es.SaveConfig(Config);
                    }
                }

                _container.Resolve <BuiltinEventConfig>().SaveConfig(Config);
                Config.SaveJson(force);
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Error, "SaveConfig: {0}", e);
                MessageBox.Show(e.ToString());
            }
        }
 public static bool TryResolve <TServiceType>(out TServiceType service) where TServiceType : class
 {
     return(_container.TryResolve <TServiceType>(out service));
 }
 public bool TryResolve <ResolveType>(out ResolveType resolvedType) where ResolveType : class
 {
     return(_container.TryResolve(out resolvedType));
 }
示例#14
0
 public bool TryResolve <T>(out T resolved) where T : class
 {
     return(_container.TryResolve <T>(out resolved));
 }