protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType <SessionManager>().As <ISessionManager>().InstancePerLifetimeScope();
            builder.RegisterType <SessionServer>().As <ISessionServer>().InstancePerLifetimeScope();

            var types = ThisAssembly.GetTypes().Where(x => typeof(IMessageFrame).IsAssignableFrom(x) && x.IsClass);

            foreach (var type in types)
            {
                var att = type.GetCustomAttributes(true).First(x => (x is MessageFrameAttribute)) as MessageFrameAttribute;
                builder
                .RegisterType(type)
                .Keyed <IMessageFrame>(att.FrameType)
                .InstancePerDependency();
            }

            builder.Register <Func <eMessageFrameType, IMessageFrame> >(c =>
            {
                var componentContext = c.Resolve <IComponentContext>();
                return((frameType) => componentContext.ResolveKeyed <IMessageFrame>(frameType));
            });

            builder.Register <Func <eSessionType, ISessionManager> >(c =>
            {
                var componentContext = c.Resolve <IComponentContext>();
                return((sessionType) => componentContext.Resolve <ISessionManager>(new NamedParameter("sessionType", sessionType)));
            });

            builder.Register <Func <eSessionType, ISessionServer> >(c =>
            {
                var componentContext = c.Resolve <IComponentContext>();
                return((sessionType) => componentContext.Resolve <ISessionServer>(new NamedParameter("sessionType", sessionType)));
            });
        }
Exemple #2
0
        protected override void Load(ContainerBuilder builder)
        {
            // 注册核心库
            // 注册 Kafka
            builder.Register(c => new KafkaService(c.Resolve <IConfiguration>().GetValue <string>("KafkaHost"),
                                                   c.Resolve <IConfiguration>().GetValue <string>("KafkaPort")))
            .As <IKafkaService>()
            .SingleInstance();
            // 注册Redis
            builder.Register(c => new RedisClient(
                                 c.Resolve <IConfiguration>().GetValue <string>("RedisHost"),
                                 c.Resolve <IConfiguration>().GetValue <string>("RedisPort")
                                 )
                             ).AsImplementedInterfaces().SingleInstance();
            // 注册Zookeeper
            builder.Register(c => ZookeeperClient.InitClientConnection(new string[] { "ali.wwbweibo.icu" }, new string[] { "2181" }))
            .As <ZookeeperClient>().SingleInstance();
            // 注册Handler
            builder.RegisterTypes(ThisAssembly.GetTypes().Where(p => p.Namespace.EndsWith("Handler")).ToArray())
            .AsSelf().PropertiesAutowired().SingleInstance();

            // 注册Service
            builder.RegisterTypes(ThisAssembly.GetTypes().Where(p => p.Namespace.EndsWith("Services")).ToArray())
            .AsSelf()
            .PropertiesAutowired()
            .SingleInstance();
        }
Exemple #3
0
 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterTypes(ThisAssembly.GetTypes())
     .AsSelf()
     .AsImplementedInterfaces()
     .SingleInstance();
 }
Exemple #4
0
        protected override void Load(ContainerBuilder builder)
        {
            var controllers = ThisAssembly.GetTypes().Where(ss => ss.FullName.StartsWith("Controllers.Controllers") && !ss.IsNested).ToArray();

            builder.RegisterTypes(controllers)
            .PropertiesAutowired();
        }
    protected override void Load(ContainerBuilder builder)
    {
        builder.RegisterType <DialogService>().As <IDialogService>().SingleInstance();
        builder.RegisterType <PluginService>().As <IPluginService>().SingleInstance();
        builder.RegisterType <ThemeService>().As <IThemeService>().SingleInstance();
        builder.RegisterType <ExternalService>().As <IExternalService>().SingleInstance();

        builder.RegisterType <MainWindowViewModel>().As <MainWindowViewModel>().SingleInstance();
        builder.RegisterType <ModSelectionViewModel>().As <IModSelectionViewModel>().SingleInstance();
        builder.RegisterType <MainEditorViewModel>().As <IMainEditorViewModel>().SingleInstance();

        ContainerProvider.ModServiceGetterFactory.AddModule(new WpfModServiceModule());

        builder.RegisterType <ModListItemViewModel>().As <IModListItemViewModel>();
        builder.RegisterType <ModListItemViewModelFactory>().As <IModListItemViewModelFactory>().SingleInstance();

        builder.RegisterType <JumpService>().As <IJumpService>().SingleInstance();

        // editor modules
        IEnumerable <Type> types = ThisAssembly
                                   .GetTypes()
                                   .Where(i => typeof(EditorModule).IsAssignableFrom(i) && !i.IsAbstract);

        foreach (Type t in types)
        {
            builder.RegisterType(t).As <EditorModule>();
        }
    }
 private Type[] GetParametrizedJobTypes()
 {
     return(ThisAssembly.GetTypes().Where(
                type => !type.IsGenericType &&
                !type.IsAbstract &&
                TypeUtils.IsFinalClassImplementationOfOpenGenericInterface(type, typeof(IJob <>)))
            .ToArray());
 }
        private void RegisterRecurringJobs(ContainerBuilder builder)
        {
            var jobs = ThisAssembly.GetTypes()
                       .Where(type => type.IsClass && !type.IsAbstract && typeof(BaseRecurringJob).IsAssignableFrom(type));

            jobs.ForEach(job => builder.RegisterType(job).AsSelf()
                         .InstancePerBackgroundJob());
        }
Exemple #8
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterTypes(ThisAssembly.GetTypes()
                                  .Where(x => typeof(Controller).IsAssignableFrom(x))
                                  .ToArray())
            .InstancePerLifetimeScope();

            base.Load(builder);
        }
Exemple #9
0
        protected override void Load(ContainerBuilder builder)
        {
            var services = from p in ThisAssembly.GetTypes() where p.FullName.StartsWith("Service.Services") && !p.IsNested select p;

            builder.RegisterTypes(services.ToArray())
            .AsImplementedInterfaces()
            .AsSelf()
            .PropertiesAutowired()
            .InstancePerLifetimeScope();
        }
        protected override void Load(ContainerBuilder builder)
        {
            var services = ThisAssembly.GetTypes()
                           .Where(s => s.IsClass)
                           .Where(s => s.DisplayName().EndsWith("Service"))
                           .Select(s => s.UnderlyingSystemType)
                           .ToList();

            services.ForEach(s => builder.RegisterType(s).AsImplementedInterfaces().InstancePerLifetimeScope());
        }
Exemple #11
0
        protected override void Load(ContainerBuilder builder)
        {
            //配置所有Controller为支持属性注入
            var assmbly     = ThisAssembly.GetTypes();
            var controllers = assmbly.Where(ss => ss.FullName.StartsWith("WebBase.Controllers") && !ss.IsNested)
                              .ToArray();

            builder.RegisterTypes(controllers)
            .PropertiesAutowired();
        }
Exemple #12
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType <ToolSelectionMenu>().SingleInstance().OnActivated(a => initMenu(a.Instance, a.Context));
            builder.RegisterType <ToolMenuBuilder>().SingleInstance();
            builder.RegisterType <ToolSelectionCategory>();
            builder.RegisterType <ToolSelectionTool>();

            builder.RegisterTypes(ThisAssembly.GetTypes().Where(t => t.IsAssignableTo <PlayerTool>()).ToArray())
            .AsSelf()
            .Keyed <PlayerTool>(type => type);
        }
Exemple #13
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterTypes(ThisAssembly.GetTypes())
            .AsSelf()
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.RegisterType <ConfigurationSettingsProvider>()
            .AsImplementedInterfaces()
            .WithParameter("configuration", builder.Properties[Configuration] !);
        }
        protected override void Load(ContainerBuilder builder)
        {
            var implementations = (from type in ThisAssembly.GetTypes()
                                   where type.IsClass && !type.IsAbstract
                                   where ServiceType.IsAssignableFrom(type)
                                   select type);

            foreach (var implementation in implementations)
            {
                builder.RegisterType(implementation).As(ServiceType);
            }
        }
Exemple #15
0
        private void RegisterViewModels(ContainerBuilder builder)
        {
            ThisAssembly.GetTypes()
            .Where(type => type.IsClass)
            .Where(type => type.Name.EndsWith("ViewModel"))
            .Where(type => type.GetInterfaces()
                   .Any(interfaceType => interfaceType.Name.StartsWith("I") && interfaceType.Name.EndsWith("ViewModel")))
            .ForEach(type => builder.RegisterType(type).AsImplementedInterfaces());

            builder.RegisterType <AlbumFolderViewModel.Factory>().As <IAlbumFolderViewModelFactory>().SingleInstance();
            builder.RegisterType <GroupFolderViewModel.Factory>().As <IGroupFolderViewModelFactory>().SingleInstance();
        }
        protected override void Load(ContainerBuilder builder)
        {
            loadConsole(builder);

            builder.RegisterType <WorldRenderingSimulator>().SingleInstance();
            builder.RegisterType <UIRenderingService>().SingleInstance();

            builder.RegisterType <WorldRenderingService>().SingleInstance();

            builder.RegisterType <ChunkedVoxelWorldRenderer>().As <IVoxelWorldRenderer>().SingleInstance();
            builder.RegisterType <InGameMeshProvider>().As <IMeshProvider>();
            builder.RegisterTypes(ThisAssembly.GetTypes().Where(t => t.IsAssignableTo <IMeshProvider>()).ToArray())
            .AsSelf();
        }
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // Register the SignalR hubs.
            builder.RegisterHubs(Assembly.GetExecutingAssembly());

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .Where(t => t.Name.EndsWith("Repository", StringComparison.Ordinal))
            .AsImplementedInterfaces();


            builder.RegisterType <FeatureApplicationServices>().AsImplementedInterfaces();
            builder.RegisterType <CommandSender>().As <ICommandSender>();

            var innerBuilder = new ContainerBuilder();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IHubBroadcasterFor).IsAssignableFrom(_)).ToArray())
            .As <IHubBroadcasterFor>();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IDatabaseBroadcasterFor).IsAssignableFrom(_)).ToArray())
            .As <IDatabaseBroadcasterFor>();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IHistoryBroadcasterFor).IsAssignableFrom(_)).ToArray())
            .As <IHistoryBroadcasterFor>();

            IContainer innerContainer = innerBuilder.Build();
            var        eventHandlers  = new IEventHandler[] {
                new DatabaseEventHandler(innerContainer.Resolve <IEnumerable <IDatabaseBroadcasterFor> >()),
                new HubEventHandler(innerContainer.Resolve <IEnumerable <IHubBroadcasterFor> >()),
                new HistoryEventHandler(innerContainer.Resolve <IEnumerable <IHistoryBroadcasterFor> >())
            };
            var dispatcher = new NEventStoreDispatcher(eventHandlers);

            var nEventStore =
                Wireup.Init()
                .LogToOutputWindow()
                .UsingSqlPersistence("FeatureBeeContext")
                .WithDialect(new MsSqlDialect())
                .InitializeStorageEngine()
                // .EnlistInAmbientTransaction()
                .UsingJsonSerialization()
                .UsingSynchronousDispatchScheduler()
                .DispatchTo(new DelegateMessageDispatcher(dispatcher.DispatchCommit))
                .Build();

            builder.RegisterInstance(nEventStore);
        }
        protected override void Load(ContainerBuilder builder)
        {
            log.Info("Configuring OpenDiablo2.Scenes service implementations.");

            var types = ThisAssembly.GetTypes().Where(x => typeof(IScene).IsAssignableFrom(x) && x.IsClass);

            foreach (var type in types)
            {
                var att = type.GetCustomAttributes(true).First(x => (x is SceneAttribute)) as SceneAttribute;
                builder
                .RegisterType(type)
                .Keyed <IScene>(att.SceneType)
                .InstancePerDependency();
            }
        }
Exemple #19
0
    protected override void Load(ContainerBuilder builder)
    {
        builder.RegisterType <CurrentModService>().As <ICurrentModService>().SingleInstance();
        builder.RegisterType <PathConverter>().AsSelf().SingleInstance();

        foreach (var type in ThisAssembly.GetTypes())
        {
            if (typeof(ICommand).IsAssignableFrom(type) && type.GetCustomAttribute <CommandAttribute>() != null)
            {
                builder.RegisterType(type).AsSelf();
            }
        }

        ContainerProvider.ModServiceGetterFactory.AddModule(new ConsoleModServiceModule());
    }
        private void loadVoxelTypes(ContainerBuilder builder)
        {
            Type[] types = ThisAssembly.GetTypes().Where(t => t.IsSubclassOf(typeof(GameVoxelType))).ToArray();
            builder.RegisterTypes(types)
            .Except <BuildingSiteType>()
            .AsSelf()
            .As <IGameVoxelType>()
            .OnActivated(
                o => ((GameVoxelType)o.Instance).InjectVoxelTypesFactory(o.Context.Resolve <VoxelTypesFactory>()))
            .SingleInstance();

            builder.RegisterType <MonumentVoxelBrain>();

            builder.RegisterType <VoxelTypesFactory>().SingleInstance();

            builder.RegisterType <ItemTypesFactory>().SingleInstance();
        }
        protected override void Load(ContainerBuilder builder)
        {
            foreach (var(service, intf) in ThisAssembly.GetTypes()
                     .Where(x => x.IsClass)
                     .Select(DefaultConvention)
                     .Where(x => x.intf != null))
            {
                Debug.WriteLine($" {service.Name} as {intf.Name}");
                builder.RegisterType(service).As(intf);
            }

            foreach (var service in ThisAssembly.GetTypes()
                     .Where(x => x.IsClass && typeof(ICmd).IsAssignableFrom(x)))
            {
                Debug.WriteLine($" {service.Name} as ICmd");
                builder.RegisterType(service);
            }
        }
Exemple #22
0
        private static List <FieldInfo> IterateOverEverything()
        {
            Assembly[]       assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.ToUpperInvariant().StartsWith("OPENYS")).ToArray();
            List <FieldInfo> FieldInfos = new List <FieldInfo>();

            foreach (Assembly ThisAssembly in assemblies)
            {
                FieldInfo[][] Temp = ThisAssembly.GetTypes().Select(y => y.GetFields(BindingFlags.Public | BindingFlags.Static)).ToArray();
                foreach (FieldInfo[] TheseFields in Temp)
                {
                    foreach (FieldInfo ThisField in TheseFields)
                    {
                        FieldInfos.Add(ThisField);
                    }
                }
            }
            return(FieldInfos);
        }
Exemple #23
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterAssemblyTypes(ThisAssembly)
            .As(type => type.GetInterfaces())
            .Where(tp =>
                   tp.Name.ToUpper().EndsWith("LOADER") ||
                   tp.Name.ToUpper().EndsWith("DATAPARSER") ||
                   tp.Name.ToUpper().EndsWith("BUILDER"))
            .InstancePerLifetimeScope();

            List <Type> geometryBuilders =
                ThisAssembly.GetTypes().ToList()
                .Where(tp => !tp.IsInterface &&
                       !tp.IsAbstract &&
                       tp.Name.ToUpper().EndsWith("BUILDER"))
                .Distinct()
                .ToList();

            List <Type> dataParsers =
                ThisAssembly.GetTypes().ToList()
                .Where(tp => !tp.IsInterface &&
                       !tp.IsAbstract &&
                       tp.Name.ToUpper().EndsWith("DATAPARSER"))
                .Distinct()
                .ToList();

            builder.Register(c => new GeometryBuilderFactory
            {
                Builders = (from geometryBuilder in geometryBuilders
                            select geometryBuilder.GetInterface("I" + geometryBuilder.Name)
                            into typeInterface
                            select c.Resolve(typeInterface) as IGeometryBuilder).ToArray()
            }).As <IGeometryBuilderFactory>().InstancePerLifetimeScope();

            builder.Register(c => new DataPackageParser
            {
                DataParsers = (from dataParser in dataParsers
                               select dataParser.GetInterface("I" + dataParser.Name)
                               into typeInterface
                               select c.Resolve(typeInterface) as IDataParser).ToArray()
            }).As <IDataPackageParser>().InstancePerLifetimeScope();
        }
Exemple #24
0
        void OnComponentActivated(object sender, ActivatedEventArgs <object> e)
        {
            var vmType = e.Instance.GetType();

            if (!vmType.FullName.EndsWith("ViewModel"))
            {
                return;
            }

            var attachmentBaseType = typeof(Attachment <>).MakeGenericType(vmType);

            var attachments = ThisAssembly.GetTypes()
                              .Where(t => InheritsFrom(t, attachmentBaseType) && e.Context.IsRegistered(t))
                              .Select(t => (IAttachment)e.Context.Resolve(t));

            foreach (var attachment in attachments)
            {
                attachment.AttachTo(e.Instance);
            }
        }
        protected override void Load(ContainerBuilder builder)
        {
            // Gamestate
            builder.RegisterType <GameState>().SingleInstance();
            builder.RegisterType <ClearGameStateChangesService>().SingleInstance();
            //builder.RegisterType<Model.World>().SingleInstance();
            builder.Register <Func <Model.World, Point2, GameVoxel> >(ctx =>
            {
                //var proxyGenerator = ctx.Resolve<ProxyGenerator>();
                return((w, p) => new GameVoxel(w, p));
            }).AsSelf().SingleInstance();

            builder.RegisterType <VoxelContentsFactory>().SingleInstance();

            // Other
            builder.RegisterType <WorldSimulationService>().SingleInstance();

            // Register all types in the Types namespaces (should be renamed to gameplay namespace)
            builder.RegisterTypes(
                ThisAssembly.GetTypes()
                .Where(
                    t =>
                    t.Namespace != null && t.Namespace.StartsWith("MHGameWork.TheWizards.GodGame.Types")).ToArray())
            .AsSelf()
            .SingleInstance();
            // Auto-load all modules in the types namespace
            var gameplayModules = ThisAssembly.GetTypes()
                                  .Where(
                t =>
                t.Namespace != null && t.Namespace.StartsWith("MHGameWork.TheWizards.GodGame.Types"))
                                  .Where(t => t.IsAssignableTo <Module>()).ToArray();

            foreach (var gameplayModule in gameplayModules)
            {
                var inst = (Module)Activator.CreateInstance(gameplayModule);
                builder.RegisterModule(inst);
            }

            loadVoxelTypes(builder);
        }
Exemple #26
0
        protected override void Load(ContainerBuilder builder)
        {
            var assembly = typeof(Application).Assembly;

            builder.RegisterControllers(assembly);
            builder.RegisterModelBinders(assembly);
            builder.RegisterModelBinderProvider();
            builder.RegisterModule(new AutofacWebTypesModule());
            builder.RegisterFilterProvider();

            var queries =
                ThisAssembly
                .GetTypes()
                .Where(x => x.Namespace != null &&
                       (x.Namespace.StartsWith("Compilify.Web.Queries", StringComparison.Ordinal) ||
                        x.Namespace.StartsWith("Compilify.Web.Commands", StringComparison.Ordinal)));

            foreach (var query in queries)
            {
                builder.RegisterType(query).AsSelf().InstancePerDependency();
            }
        }
Exemple #27
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            var configTypes = ThisAssembly.GetTypes()
                              .Where(t => t?.Namespace?.StartsWith("DataCollector.Config",
                                                                   StringComparison.InvariantCultureIgnoreCase) ?? false);

            foreach (var configType in configTypes)
            {
                builder.Register(c =>
                {
                    var configurationRoot = c.Resolve <IConfigurationRoot>();
                    var configSectionName = configType.Name.Replace("Configuration", "").Replace("Config", "");

                    var configuration = Activator.CreateInstance(configType);
                    configurationRoot.GetSection(configSectionName).Bind(configuration);

                    return(configuration);
                })
                .As(configType)
                .SingleInstance();
            }
        }
Exemple #28
0
 public static Type TypeOfNameString(String TypeName, Boolean BroadSearch)
 {
     TypeName = TypeName.Replace("\\+", "+");
     if (BroadSearch)
     {
         ArrayList  TheseTypes        = new ArrayList();
         Assembly[] RawAssemblies     = AppDomain.CurrentDomain.GetAssemblies();
         ArrayList  OrderedAssemblies = new ArrayList();
         OrderedAssemblies.Add(Assembly.GetExecutingAssembly());
         OrderedAssemblies.Add(typeof(Shell).Assembly);
         OrderedAssemblies.Add(typeof(Game).Assembly);
         foreach (Assembly A in RawAssemblies)
         {
             if (!OrderedAssemblies.Contains(A))
             {
                 OrderedAssemblies.Add(A);
             }
         }
         foreach (Assembly ThisAssembly in OrderedAssemblies)
         {
             foreach (Type AssType in ThisAssembly.GetTypes())
             {
                 TheseTypes.Add(AssType);
             }
         }
         foreach (Type T in TheseTypes)
         {
             if (T.Name.ToUpper() == TypeName.ToUpper())
             {
                 TypeName = T.AssemblyQualifiedName;
                 break;
             }
         }
     }
     return(Type.GetType(TypeName, false, false));
 }
Exemple #29
0
 private IEnumerable <Type> GetSubClassesOf <T>()
 {
     return(ThisAssembly.GetTypes()
            .Where(t => t != typeof(T) && typeof(T).IsAssignableFrom(t))
            .ToList());
 }