コード例 #1
0
 public BusinessControllerBase SelectBusinessController(HttpRequestMessage request, ITypeListHost host, INamingConvention convention, IInjectionContainer container)
 {
     UrlParser url = new UrlParser(request.RequestUri.ToString());
     Type controllerType = host.BusinessTypeList[url.BusinessClass];
     var instance = container.Resolve(controllerType);
     return new CrowBusinessController(instance, url, convention);
 }
コード例 #2
0
ファイル: Crow.cs プロジェクト: msusur/Crowfx
        public void Install(IInjectionContainer container, IQueryStore queryStore)
        {
            container.Bind<IBusiness, DataBusiness>();
            queryStore.ConnectionString = new Crow.Library.Foundation.Common.ConnectionStringInformation("Data Source=.;Initial Catalog=Test;User Id=sa;Password=Aa123456");

            queryStore.Expression<IDataRepository, Data>("GetDataById").Where<int>((m, id) => m.Id == id).AddToStore();
        }
コード例 #3
0
ファイル: CrowHost.cs プロジェクト: msusur/Crowfx
 /// <summary>
 /// Initializes a new instance of <see cref="CrowHost"/>.
 /// </summary>
 /// <param name="log">Instance of logger.</param>
 /// <param name="convention">Naming convention instance.</param>
 /// <param name="container">Dependency injection container.</param>
 /// <param name="configuration">Configuration helper.</param>
 /// <param name="host">Http host instance.</param>
 public CrowHost(ILog log, INamingConvention convention,
                 IInjectionContainer container,
                 IConfigurationHelper configuration,
                 IHttpHost host)
     : base(log, convention, container, configuration, host)
 {
 }
コード例 #4
0
ファイル: CrowHost.cs プロジェクト: msusur/Crowfx
 /// <summary>
 /// Configures the host with default port 80.
 /// </summary>
 public static ICrowHttpHost ConfigureHost(IInjectionContainer container, string baseUrl)
 {
     var configuration = container.Resolve<IConfigurationHelper>();
     var port = configuration.Get<int>(Strings.Configuration.HostingPort, Strings.Defaults.DefaultPort);
     var host = baseUrl;
     var isHttps = configuration.Get<bool>(Strings.Configuration.HostingIsHttps, false);
     return ConfigureHost(container, host, port, isHttps);
 }
コード例 #5
0
ファイル: CrowHost.cs プロジェクト: msusur/Crowfx
 /// <summary>
 /// Configures the host with default configuration.
 /// Port: 80 and baseurl : localhost
 /// </summary>
 public static ICrowHttpHost ConfigureHost(IInjectionContainer container)
 {
     var configuration = container.Resolve<IConfigurationHelper>();
     var port = configuration.Get(Strings.Configuration.HostingPort, Strings.Defaults.DefaultPort);
     var host = configuration.Get(Strings.Configuration.HostingHostname, Strings.Defaults.DefaultHostname);
     var isHttps = configuration.Get(Strings.Configuration.HostingIsHttps, false);
     return ConfigureHost(container, host, port, isHttps);
 }
コード例 #6
0
        public void OnUnregister(IInjectionContainer container)
        {
            //Unbinds the command dispatcher and pool.
            container.Unbind<ICommandDispatcher>();
            container.Unbind<ICommandPool>();

            //Unbinds all commands, if there's any.
            container.Unbind<ICommand>();
        }
コード例 #7
0
        public void OnUnregister(IInjectionContainer container)
        {
            container.afterAddBinding -= this.OnAfterAddBinding;
            container.bindingResolution -= this.OnBindingResolution;

            disposable.Clear();
            updateable.Clear();
            MonoBehaviour.Destroy(eventCaller);
        }
コード例 #8
0
 public void OnRegister(IInjectionContainer container)
 {
     //Binds the command dispatcher to a singleton, so every command can
     //receive the instance.
     container.Bind<ICommandDispatcher>().ToSingleton<CommandDispatcher>();
     //Binds the command pool to the CommandDispatcher.
     var dispatcher = (CommandDispatcher)container.Resolve<ICommandDispatcher>();
     container.Bind<ICommandPool>().To<CommandDispatcher>(dispatcher);
 }
コード例 #9
0
ファイル: CubeFactory.cs プロジェクト: NotYours180/adic
        /// <summary>
        /// Initializes a new instance of the <see cref="Adic.Examples.Factories.Bindings.CubeFactory"/> class.
        /// </summary>
        /// <param name="container">Container in which the factory is bounded.</param>
        public CubeFactory(IInjectionContainer container)
        {
            this.container = container;

            //To make instantiation easier, binds the "Cube" behaviour
            //to the "Cube" prefab.
            //In this example, "Cube" is not in the prefab and will be
            //added during resolution.
            this.container.Bind<Cube>().ToPrefab("07_Factory/Cube");
        }
コード例 #10
0
ファイル: HostInstaller.cs プロジェクト: msusur/Crowfx
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     container.Bind<IHttpHost, AspNetSelfHosting>();
     container.Bind<ICrowHttpHandler, HttpCrowDispatcher>();
     container.Bind<INamingConvention, DefaultNamingConvention>();
     container.Bind<ICrow, CrowDocumentationController>();
     container.Bind<ICrowHttpHost, CrowHost>();
     container.Bind<IHostConfiguration, HostConfiguration>();
     container.Bind<IBusinessControllerSelector, CrowBusinessControllerSelector>();
 }
コード例 #11
0
ファイル: PrefabBindings.cs プロジェクト: NotYours180/adic
 public void SetupBindings(IInjectionContainer container)
 {
     container
         //Bind the "CubeA" prefab.
         .Bind<Transform>().ToPrefabSingleton("06_BindingsSetup/CubeA")
         //Bind the "CubeB" prefab.
         .Bind<Transform>().ToPrefabSingleton("06_BindingsSetup/CubeB")
         //Bind the "CubeC" prefab.
         .Bind<Transform>().ToPrefabSingleton("06_BindingsSetup/CubeC");
 }
コード例 #12
0
ファイル: CrowHost.cs プロジェクト: msusur/Crowfx
 /// <summary>
 /// Configures the host with the given baseurl and port.
 /// </summary>
 public static ICrowHttpHost ConfigureHost(IInjectionContainer container, string baseUrl, int port, bool isHttps = false)
 {
     var host = container.Resolve<ICrowHttpHost>();
     var configuration = container.Resolve<IHostConfiguration>();
     configuration.BaseUrl = baseUrl;
     configuration.IsHttps = isHttps;
     configuration.Port = port;
     host.Configure(configuration);
     return host;
 }
コード例 #13
0
        /// <summary>
        /// 在容器中绑定一个以指定类型为值,ICommand 为 type 的 binding.
        /// 执行后,可调用 PoolCommands 方法来储存所有 command 到对象池.
        /// RegisterCommands 方法用于使 command 准备进入对象池.
        /// </summary>
        public static IInjectionContainer RegisterCommand(this IInjectionContainer container, Type type)
        {
            if (!type.IsClass && type.IsAssignableFrom(typeof(ICommand)))
            {
                throw new Exceptions(Exceptions.TYPE_NOT_A_COMMAND);
            }

            container.Bind <ICommand>().To(type);

            return(container);
        }
コード例 #14
0
        /// <summary>
        /// 注销容器
        /// </summary>
        public void OnUnregister(IInjectionContainer container)
        {
            // 取消 AOT 委托
            container.afterAddBinding  -= this.OnAfterAddBinding;
            container.afterInstantiate -= this.OnBindingResolution;

            // 释放 list 并销毁组件
            disposable.Clear();
            updateable.Clear();
            MonoBehaviour.Destroy(eventBehaviour);
        }
コード例 #15
0
        public void OnRegister(IInjectionContainer container)
        {
            // 创建一条 CommandDispatcher 实例
            CommandDispatcher dispatcher = new CommandDispatcher(container);

            // 将实例绑定到绑定一个单例的 ICommandDispatcher binding
            container.BindSingleton <ICommandDispatcher>().To(dispatcher);
            // 再将实例绑定到一个 ICommandPool binding,此时 container 中将有两条 binding
            // 都为单例类型,且值都为 dispatcher,只有类型不同
            container.BindSingleton <ICommandPool>().To(dispatcher);
        }
コード例 #16
0
ファイル: SampleModule.cs プロジェクト: msusur/Crowfx
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     string provider = "System.Data.SqlClient";
     string connectionString = "Data Source=.;Initial Catalog=Test;User Id=sa;Password=Aa123456";
     queryStore.ConnectionString = new ConnectionStringInformation(connectionString, provider);
     queryStore.Expression<IDataRepository, Data>("LoadDataById")
                  .Select()
                  .Where<int>((data, id) => data.Id == id)
                  .OrderBy((d) => d.Id)
                  .AddToStore();
     container.Bind<IDataBusiness, DataBusinessClass>();
 }
コード例 #17
0
        static void Main(string[] args)
        {
            var bootstrapper = new UnityBootstrapper();
            IInjectionContainer container = bootstrapper.GetContainer();
            var mgr = new GenericManager(container);

            Console.WriteLine(mgr.GetOutput1());
            Console.WriteLine(mgr.GetOutput2());
            Console.WriteLine(mgr.GetOutput3());

            Console.Read();
        }
コード例 #18
0
        public Application(IInjectionContainer container)
        {
            this.container = container;

            RegisterViewModels();

            RegisterServices();

            Initialize();

            DisplayRootView <MasterView>();
            //DisplayRootViewFor<ProjectListViewModel>();
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Adic.CommandDispatcher"/> class.
        /// </summary>
        /// <param name="container">Dependency injection container that created the command dispatcher.</param>
        public CommandDispatcher(IInjectionContainer container)
        {
            this.commands           = new Dictionary <Type, object>();
            this.container          = container;
            this.commandsToRegister = new List <Type>();

            this.eventCallerExtension = this.container.GetExtension <EventCallerContainerExtension>();
            if (eventCallerExtension == null)
            {
                this.container.RegisterExtension <EventCallerContainerExtension>();
                this.eventCallerExtension = this.container.GetExtension <EventCallerContainerExtension>();
            }
        }
コード例 #20
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            IIocBootstrapper    bootstrapper = new UnityBootstrapper();
            IInjectionContainer container    = bootstrapper.GetContainer();

            DependencyResolver.SetResolver(new IocDependencyResolver(container));
        }
コード例 #21
0
ファイル: CrowBusinessHandler.cs プロジェクト: msusur/Crowfx
        /// <summary>
        /// Initializes a new instance of <see cref="CrowBusinessHandler"/>.
        /// </summary>
        public CrowBusinessHandler(ITypeListHost host,
                                    INamingConvention convention,
                                    IInjectionContainer container)
        {
            _host = host;
            _host.ThrowIfNull("host");

            _convention = convention;
            _convention.ThrowIfNull("convention");

            _container = container;
            _container.ThrowIfNull("container");
        }
コード例 #22
0
 /// <summary>
 /// Installs the crow components.
 /// </summary>
 /// <param name="container"></param>
 /// <param name="queryStore"></param>
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     container.Bind<ILog, DefaultLogger>();
     container.Bind<IFileOperations, FSFileOperations>();
     container.Bind<IConfigurationHelper, ApplicationConfigurationHelper>();
     container.Bind<IMessagingService, DebugMessagesService>();
     container.Bind<IAccountService, UnsafeAccountService>();
     container.Bind<IDialectProvider, SqlDialectProvider>();
     container.Bind<ICacheManager, InMemoryCacheManager>();
     container.Bind<ITemplateEngine, PoorMansTemplating>();
     container.Bind<IAssemblyLoader, FileAssemblyLoader>();
     container.Bind<IItemManager, ThreadItemManager>();
 }
コード例 #23
0
 public void SetupBindings(IInjectionContainer container)
 {
     container
     .Bind <CubeRotationSpeed>().To(new CubeRotationSpeed(0.5f)).When(
         context => context.parentInstance is MonoBehaviour &&
         ((MonoBehaviour)context.parentInstance).name.Contains("CubeA"))
     .Bind <CubeRotationSpeed>().To(new CubeRotationSpeed(2.0f)).When(
         context => context.parentInstance is MonoBehaviour &&
         ((MonoBehaviour)context.parentInstance).name.Contains("CubeB"))
     .Bind <CubeRotationSpeed>().To(new CubeRotationSpeed(4.5f)).When(
         context => context.parentInstance is MonoBehaviour &&
         ((MonoBehaviour)context.parentInstance).name.Contains("CubeC"));
 }
コード例 #24
0
        public void TestMethod1()
        {
            var bootstrapper = new UnityBootstrapper();
            IInjectionContainer container = bootstrapper.GetContainer();
            var mgr = new GenericManager(container);

            string val1 = mgr.GetOutput1();
            string val2 = mgr.GetOutput2();
            string val3 = mgr.GetOutput3();

            Assert.AreEqual(val1, new MockClass1().Val);
            Assert.AreEqual(val2, new MockClass2().Val);
            Assert.AreEqual(val3, new MockClass3().Val);
        }
コード例 #25
0
        public void OnRegister(IInjectionContainer container)
        {
            this.CreateBehaviour(container.identifier);

            // Check whether a binding for the ICommandDispatcher exists.
            if (container.ContainsBindingFor <ICommandDispatcher>())
            {
                var dispatcher = container.Resolve <ICommandDispatcher>();
                BindUnityExtension(disposable, dispatcher);
            }

            container.afterAddBinding   += this.OnAfterAddBinding;
            container.bindingResolution += this.OnBindingResolution;
        }
コード例 #26
0
ファイル: DataBindings.cs プロジェクト: NotYours180/adic
 public void SetupBindings(IInjectionContainer container)
 {
     container
         //Bind the rotation data for "CubeA".
         .Bind<CubeRotationSpeed>().To(new CubeRotationSpeed(0.5f)).When(
             context => context.parentInstance is MonoBehaviour &&
                 ((MonoBehaviour)context.parentInstance).name.Contains("CubeA"))
         //Bind the rotation data for "CubeB".
         .Bind<CubeRotationSpeed>().To(new CubeRotationSpeed(2.0f)).When(
             context => context.parentInstance is MonoBehaviour &&
                 ((MonoBehaviour)context.parentInstance).name.Contains("CubeB"))
         //Bind the rotation data for "CubeC".
         .Bind<CubeRotationSpeed>().To(new CubeRotationSpeed(4.5f)).When(
             context => context.parentInstance is MonoBehaviour &&
                 ((MonoBehaviour)context.parentInstance).name.Contains("CubeC"));
 }
コード例 #27
0
        public void TestInitialize()
        {
            // mock:
            _traceConfig = new TraceConfig
            {
                TraceBehavior       = TraceStaticBehavior.AddListenerToStaticAccessAndRemoveDefaultTracer,
                PageSize            = 1000,
                MaximumTimeForFlush = TimeSpan.FromSeconds(5)
            };

            // instance de test:
            _container = new InjectionContainerSimpleInjector();

            // enregistre le type de la classe de test
            _container.Register <IClassVoidTest, ClassVoidTest>(LifeTime.Singleton);
        }
コード例 #28
0
        public void OnRegister(IInjectionContainer container)
        {
            //Adds the container to the disposable list.
            disposable.Add(container);

            //Checks whether a binding for the ICommandDispatcher exists.
            if (container.ContainsBindingFor<ICommandDispatcher>()) {
                var dispatcher = container.Resolve<ICommandDispatcher>();
                if (dispatcher is IDisposable) {
                    disposable.Add((IDisposable)dispatcher);
                }
            }

            container.afterAddBinding += this.OnAfterAddBinding;
            container.bindingResolution += this.OnBindingResolution;
        }
コード例 #29
0
        /// <summary>
        /// 为指定命名空间中实现了 IBindingsSetup 接口的类型在容器中实例化并注入,再按优先级排序,最后按
        /// 顺序执行它们自身所实现的 SetupBindings 方法
        /// </summary>
        public static IInjectionContainer SetupBindings(this IInjectionContainer container,
                                                        string namespaceName,
                                                        bool includeChildren)
        {
            // 获取指定命名空间中实现了 IBindingsSetup 接口的类型数组
            var setups = TypeUtils.GetAssignableTypes(
                typeof(IBindingsSetup), namespaceName, includeChildren);
            // 新建一个和获取到的类型数组同等长度的内部类数组
            var prioritizedSetups = new PrioritizedSetup[setups.Length];

            for (var i = 0; i < setups.Length; i++)
            {
                // 使用指定容器获取类型的经过注入后的类型实例
                var setup      = (IBindingsSetup)container.Resolve(setups[i]);
                var attributes = setup.GetType().GetCustomAttributes(typeof(Priority), true);

                // 如果获取到了[Priority]特性,就将类型的实例和其优先级数字新建为一个新的内部类加入数组
                if (attributes.Length > 0)
                {
                    var bindingPriority = attributes[0] as Priority;
                    prioritizedSetups[i] = new PrioritizedSetup()
                    {
                        setup    = setup,
                        priority = bindingPriority.priority
                    };
                }
                else
                {
                    // 如果没有获取到,就用实例和优先级数字0来新建一个内部类加入数组
                    prioritizedSetups[i] = new PrioritizedSetup()
                    {
                        setup    = setup,
                        priority = 0
                    };
                }
            }

            // 对数组进行排序
            Array.Sort(prioritizedSetups);
            // 逐一执行 setup 对象所实现的 SetupBindings 方法
            for (var setupIndex = 0; setupIndex < prioritizedSetups.Length; setupIndex++)
            {
                prioritizedSetups[setupIndex].setup.SetupBindings(container);
            }

            return(container);
        }
コード例 #30
0
ファイル: InjectionUtil.cs プロジェクト: lmlynik/cardgame
        /// <summary>
        /// Determines if the object is a singleton in a given container.
        /// </summary>
        /// <param name="obj">Target object to check.</param>
        /// <param name="container">Container to check for bindings.</param>
        /// <returns><c>true</c> if is singleton on container the specified obj container; otherwise, <c>false</c>.</returns>
        public static bool IsSingletonOnContainer(object obj, IInjectionContainer container)
        {
            var isSingleton = false;
            var bindings = container.GetBindingsFor(obj.GetType());

            if (bindings == null) return false;

            for (var index = 0; index < bindings.Count; index++) {
                var binding = bindings[index];

                if (binding.value == obj) {
                    isSingleton = true;
                }
            }

            return isSingleton;
        }
コード例 #31
0
ファイル: RouteExtensions.cs プロジェクト: msusur/Crowfx
        public static RouteBase MapBusiness(this RouteCollection routes, string url, IInjectionContainer container)
        {
            INamingConvention convention = container.Resolve<INamingConvention>();
            BusinessInvoker invoker = new BusinessInvoker(AspNetRoutedHost.HostList, convention, container);
            string routeUrl = url;
            if (!routeUrl.EndsWith("/"))
            {
                routeUrl += "/{*operation}";
            }

            routeUrl = routeUrl.TrimStart('~').TrimStart('/');

            var route = new Route(routeUrl, new CrowRouteHandler(invoker));

            routes.Add("Crow", route);

            return route;
        }
コード例 #32
0
        /// <summary>
        /// Register all commands from a given namespace.
        /// </summary>
        /// <param name="container">The container in which the command will be registered.</param>
        /// <param name="includeChildren">Indicates whether child namespaces should be included.</param>
        /// <param name="namespaceName">Namespace name.</param>
        /// <returns>The injection container for chaining.</returns>
        public static IInjectionContainer RegisterCommands(this IInjectionContainer container,
                                                           string namespaceName,
                                                           bool includeChildren)
        {
            var commands = TypeUtils.GetAssignableTypes(typeof(ICommand), namespaceName, includeChildren);

            if (commands.Length > 0)
            {
                var pool = container.Resolve <ICommandPool>();

                for (var cmdIndex = 0; cmdIndex < commands.Length; cmdIndex++)
                {
                    pool.AddCommand(commands[cmdIndex]);
                }
            }

            return(container);
        }
コード例 #33
0
        public void OnRegister(IInjectionContainer container)
        {
            //Adds the container to the disposable list.
            disposable.Add(container);

            //Checks whether a binding for the ICommandDispatcher exists.
            if (container.ContainsBindingFor <ICommandDispatcher>())
            {
                var dispatcher = container.Resolve <ICommandDispatcher>();
                if (dispatcher is IDisposable)
                {
                    disposable.Add((IDisposable)dispatcher);
                }
            }

            container.afterAddBinding   += this.OnAfterAddBinding;
            container.bindingResolution += this.OnBindingResolution;
        }
コード例 #34
0
 /// <summary>
 /// 整理储存所有容器
 /// </summary>
 virtual protected void ContainersStoring(IInjectionContainer container)
 {
     if (container.id != null)
     {
         if (!containersDic.ContainsKey(container.id))
         {
             containersDic[container.id] = container;
         }
         else
         {
             throw new Exceptions(Exceptions.SAME_OBJECT);
         }
     }
     else
     {
         containersDic[ContainerNullId.Null] = container;
     }
 }
コード例 #35
0
        public void OnUnregister(IInjectionContainer container)
        {
            container.afterAddBinding   -= this.OnAfterAddBinding;
            container.bindingResolution -= this.OnBindingResolution;

            if (behaviour != null && behaviour.gameObject != null)
            {
                MonoBehaviour.DestroyImmediate(behaviour.gameObject);
            }
            behaviour = null;

            disposable.Clear();
            updateable.Clear();
            lateUpdateable.Clear();
            fixedUpdateable.Clear();
            focusable.Clear();
            pausable.Clear();
            quitable.Clear();
        }
コード例 #36
0
        /// <summary>
        /// Setups bindings in the container from a given <paramref name="namespace"/>.
        /// </summary>
        /// <param name="container">Container in which the bindings will be setup.</param>
        /// <param name="namespaceName">Namespace name.</param>
        /// <param name="includeChildren">Indicates whether child namespaces should be included.</param>
        /// <param name="setup">The bindings setup.</param>
        /// <returns>The injection container for chaining.</returns>
        public static IInjectionContainer SetupBindings(this IInjectionContainer container,
                                                        string namespaceName,
                                                        bool includeChildren)
        {
            var setups = TypeUtils.GetAssignableTypes(
                typeof(IBindingsSetup), namespaceName, includeChildren);
            var prioritizedSetups = new PrioritizedBindingSetup[setups.Length];

            //Adds setups to "priority" with priority definitions.
            for (var setupIndex = 0; setupIndex < setups.Length; setupIndex++)
            {
                var setup      = (IBindingsSetup)container.Resolve(setups[setupIndex]);
                var attributes = setup.GetType().GetCustomAttributes(typeof(BindingPriority), true);

                if (attributes.Length > 0)
                {
                    var bindindPriority = attributes[0] as BindingPriority;
                    prioritizedSetups[setupIndex] = new PrioritizedBindingSetup()
                    {
                        setup    = setup,
                        priority = bindindPriority.priority
                    };
                }
                else
                {
                    //If the binding has no priority, saves it with priority 0.
                    prioritizedSetups[setupIndex] = new PrioritizedBindingSetup()
                    {
                        setup    = setup,
                        priority = 0
                    };
                }
            }

            //Orders the priority list and executes the setups.
            prioritizedSetups = prioritizedSetups.OrderByDescending(setup => setup.priority).ToArray();
            for (var setupIndex = 0; setupIndex < prioritizedSetups.Length; setupIndex++)
            {
                prioritizedSetups[setupIndex].setup.SetupBindings(container);
            }

            return(container);
        }
コード例 #37
0
ファイル: Global.asax.cs プロジェクト: Jork/Billboard
        protected void Application_Start()
        {
            _container = new InjectionContainer();

            // register some MVC objects required for configuration
            _container.Register(GlobalFilters.Filters);
            _container.Register(RouteTable.Routes);
            _container.Register(BundleTable.Bundles);
            _container.Register(GlobalConfiguration.Configuration);
            _container.Register(GlobalHost.ConnectionManager);

            // AreaRegistration.RegisterAllAreas();

            // let all configurable items, configure themselfs.
            var configurables = _container.GetExportedValues<IStartupConfiguration>();
            foreach (IStartupConfiguration configurable in configurables)
                configurable.Configure();

            GlobalConfiguration.Configuration.EnsureInitialized();
        }
コード例 #38
0
ファイル: InjectorTests.cs プロジェクト: cgarciae/adic
        public void Init()
        {
            this.injector = new InjectionContainer();
            this.binder = this.injector as IBinder;

            //Binds some objects to use on tests.
            binder.Bind<IMockInterface>().To<MockIClassWithAttributes>();
            binder.Bind<MockIClassWithoutAttributes>().ToSingleton().As("singleton");
            binder.Bind<MockIClass>().ToSingleton();

            this.containerIdentifierTests = new InjectionContainer();
            var mockClass1 = new MockIClass() { property1 = "MockClass1" };
            var mockClass2 = new MockIClassWithoutAttributes() { property1 = "MockClass2" };
            var mockClass3 = new MockIClassWithAttributes() { property1 = "MockClass3" };
            this.containerIdentifierTests.Bind<MockIClass>().To(mockClass1).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind<MockIClassWithoutAttributes>().To(mockClass2).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind<MockIClassWithAttributes>().To(mockClass3).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass1).As(TestIdentifier.MockClass1);
            this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass2).As(TestIdentifier.MockClass2);
            this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass3).As(TestIdentifier.MockClass3);
            this.containerIdentifierTests.Bind<IMockInterface>().To<MockIClass>().As(TestIdentifier.MockClassSingle);
        }
コード例 #39
0
        protected override void Configure()
        {
            winContainer = new WinRTContainer();
            container    = new SimpleInjectionContainer(winContainer);
            winContainer.RegisterWinRTServices();

            container.
            Singleton <Application>();

            RegisterServices().ContinueWith(result =>
            {
                Coroutine.Completed += (s, e) =>
                {
                    if (e.Error == null)
                    {
                        return;
                    }

                    Debug.Write(e.Error.Message);
                };
            });
        }
コード例 #40
0
        /// <summary>
        /// Register all commands from a given namespace.
        ///
        /// After registration, all commands are pooled.
        /// </summary>
        /// <param name="container">The container in which the command will be registered.</param>
        /// <param name="includeChildren">Indicates whether child namespaces should be included.</param>
        /// <param name="namespaceName">Namespace name.</param>
        /// <returns>The injection container for chaining.</returns>
        public static IInjectionContainer RegisterCommands(this IInjectionContainer container,
                                                           string namespaceName,
                                                           bool includeChildren)
        {
            var commands = TypeUtils.GetAssignableTypesInNamespace(typeof(ICommand), namespaceName, includeChildren);

            if (commands.Length > 0)
            {
                for (var cmdIndex = 0; cmdIndex < commands.Length; cmdIndex++)
                {
                    var commandType = commands[cmdIndex];
                    if (!commandType.IsAbstract)
                    {
                        container.Bind <ICommand>().To(commandType);
                    }
                }

                PoolCommands(container);
            }

            return(container);
        }
コード例 #41
0
        /// <summary>
        /// 注册容器
        /// </summary>
        public void OnRegister(IInjectionContainer container)
        {
            // 将容器添加到 IDisposable list.
            disposable.Add(container);

            // 如果容器中含有 ICommandDispatcher 类型的 binding,且它实现了 IDisposable 接口
            // 就获取它的 ICommandDispatcher 类型实例并将其也添加到 IDisposable list
            var commandDispatches = container.GetTypes <ICommandDispatcher>();

            if (commandDispatches != null && commandDispatches.Count != 0)
            {
                var dispatcher = container.Resolve <ICommandDispatcher>();
                if (dispatcher is IDisposable)
                {
                    disposable.Add((IDisposable)dispatcher);
                }
            }

            // 添加 AOT 委托
            container.afterAddBinding  += this.OnAfterAddBinding;
            container.afterInstantiate += this.OnBindingResolution;
        }
コード例 #42
0
ファイル: InstallerTests.cs プロジェクト: msusur/Crowfx
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     _isInstalled = true;
     installerstack.Push("Child");
 }
コード例 #43
0
 public void Init(IInjectionContainer container)
 {
     // Does nothing.
 }
コード例 #44
0
 public IocDependencyResolver(IInjectionContainer container)
 {
     _container = container;
 }
コード例 #45
0
ファイル: InstallerTests.cs プロジェクト: msusur/Crowfx
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     installerstack.Push("Parent");
 }
コード例 #46
0
 public void OnUnregister(IInjectionContainer container)
 {
     container.beforeAddBinding -= this.OnBeforeAddBinding;
     container.bindingEvaluation -= this.OnBindingEvaluation;
 }
コード例 #47
0
 public InjectionControllerFactory(IInjectionContainer container)
 {
     Contract.Requires<ArgumentNullException>(container != null);
     _container = container;
 }
コード例 #48
0
ファイル: BusinessInvoker.cs プロジェクト: msusur/Crowfx
 public BusinessInvoker(ITypeListHost host, INamingConvention convention, IInjectionContainer container)
 {
     _host = host;
     _convention = convention;
     _container = container;
 }
コード例 #49
0
ファイル: RouteExtensions.cs プロジェクト: msusur/Crowfx
 public static RouteBase MapBusiness(this RouteCollection routes, IInjectionContainer container)
 {
     return MapBusiness(routes, "~/crow", container);
 }
コード例 #50
0
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     container.Bind<ITestBusiness, TestBusiness>();
 }
コード例 #51
0
ファイル: HostingTests.cs プロジェクト: msusur/Crowfx
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     container.Bind<IFakeUserBusiness, FakeUserBusiness>();
 }
コード例 #52
0
ファイル: FactoryBindings.cs プロジェクト: NotYours180/adic
 public void SetupBindings(IInjectionContainer container)
 {
     //Bind "GameObject" to the "CubeFactory".
     container.Bind<GameObject>().ToFactory<CubeFactory>();
 }