Example #1
0
        public void OnRegister(IInjectionContainer container)
        {
            // Bind the command dispatcher to a singleton, so every command can receive the instance.
            container.Bind <ICommandDispatcher>().ToSingleton <CommandDispatcher>();
            // Bind the command pool to the CommandDispatcher.
            var dispatcher = (CommandDispatcher)container.Resolve <ICommandDispatcher>();

            container.Bind <ICommandPool>().To <CommandDispatcher>(dispatcher);
        }
 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);
 }
Example #3
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>();
 }
Example #4
0
        /// <summary>
        /// 在容器中绑定指定命名空间中的所有类型为值,ICommand 为 type 的多个 binding,再将其存入对象池
        /// </summary>
        public static IInjectionContainer RegisterCommands(this IInjectionContainer container,
                                                           string namespaceName,
                                                           bool includeChildren)
        {
            // 获取指定命名空间下实现了 ICommand 的类型
            var commands = TypeUtils.GetAssignableTypes(typeof(ICommand), namespaceName, includeChildren);

            // 如果不为空,就讲其类型作为值逐一绑定一条 ICommand 类型的 TEMP binding
            if (commands.Length > 0)
            {
                for (var i = 0; i < commands.Length; i++)
                {
                    var commandType = commands[i];
                    if (!commandType.IsAbstract)
                    {
                        container.Bind <ICommand>().To(commandType);
                    }
                }
                // 为容器实例化一个 ICommandPool(CommandDispatcher)实例,并将容器内的所有 commands
                // 实例化、注入并存入对象池(储存为 List<ICommand> 并根据类型添加到 CommandDispatcher
                // 的字典中)
                PoolCommands(container);
            }

            return(container);
        }
Example #5
0
        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();
        }
Example #6
0
 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");
 }
Example #7
0
 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");
 }
Example #8
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);
        }
Example #9
0
 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>();
 }
Example #10
0
 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>();
 }
 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"));
 }
Example #12
0
        /// <summary>
        /// Register a command for a given type.
        /// </summary>
        /// <param name="commandType">Type to be registered.</param>
        private void RegisterCommand(Type commandType)
        {
            if (!commandType.IsClass && commandType.IsAssignableFrom(typeof(ICommand)))
            {
                throw new CommandException(CommandException.TYPE_NOT_A_COMMAND);
            }

            if (!commandType.IsAbstract)
            {
                container.Bind <ICommand>().To(commandType);
                this.PoolCommand(commandType);
            }
        }
Example #13
0
 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"));
 }
Example #14
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);
        }
Example #15
0
 private void BindControllers(IInjectionContainer container)
 {
     container
     .Bind <IUserTouchController>().To <UserTouchController>()
     .Bind <IVehicleController>().To <VehicleController>();
 }
Example #16
0
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     container.Bind<ITestBusiness, TestBusiness>();
 }
Example #17
0
 public void SetupBindings(IInjectionContainer container)
 {
     //Bind "GameObject" to the "CubeFactory".
     container.Bind<GameObject>().ToFactory<CubeFactory>();
 }
 public void SetupBindings(IInjectionContainer container)
 {
     // Bind "GameObject" to the "CubeFactory".
     container.Bind <GameObject>().ToFactory <CubeFactory>();
 }
Example #19
0
 public void Install(IInjectionContainer container, IQueryStore queryStore)
 {
     container.Bind<IFakeUserBusiness, FakeUserBusiness>();
 }