Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public object GetService(Type serviceType)
        {
            object resolvedType = null;

            Container.TryResolve(serviceType, out resolvedType);
            return(resolvedType);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            IController resolvedType = null;

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

            config.Configure(container);

            object obj;
            container.TryResolve(typeof(IUrlModifier), out obj).ShouldBeFalse();
        }
Ejemplo n.º 6
0
        private void CopyServerUrlToClipboard()
        {
            IClipboard clipboard;

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

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

            config.Configure(container);

            object obj;

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

            return(instance);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 14
0
 public bool TryResolve <T>(out T resolved) where T : class
 {
     return(_container.TryResolve <T>(out resolved));
 }