コード例 #1
0
        public static DependencyCollection AddMapper(this DependencyCollection dependencies)
        {
            var contract       = typeof(IMapper <>);
            var implementation = typeof(CompiledMapper <>);

            dependencies.AddFactory(new GenericFactory(contract, implementation, DependencyLifetime.Singleton));

            return(dependencies);
        }
コード例 #2
0
        public static DependencyCollection AddMetrics(this DependencyCollection dependencies)
        {
            dependencies
            .AddFactory <IMetricsProvider, MetricsProvider>(metricsProvider => metricsProvider
                                                            .Lifetime(DependencyLifetime.Singleton)
                                                            .CreateIf <NullSettingsProvider>(engine => !engine.Contains(typeof(ICounter))));

            return(dependencies);
        }
コード例 #3
0
        public static DependencyCollection AddEmitter(this DependencyCollection dependencies)
        {
            dependencies
            .AddFactory(new CommandPipelineFactory())
            .AddFactory(new NotificationPipelineFactory())
            .AddFactory(new QueryPipelineFactory())
            .AddDependency(new[] { typeof(IEmitter) }, provider => new Emitter(provider), DependencyLifetime.Scoped);

            return(dependencies);
        }
コード例 #4
0
        internal static DependencyCollection AddFactory <TContract, TImplementation>(
            this DependencyCollection dependencies,
            Func <DependencyFactoryBuilder, DependencyFactoryBuilder> buildAction)
            where TImplementation : class, TContract
        {
            var builder = buildAction(new DependencyFactoryBuilder(typeof(TContract), typeof(TImplementation)));

            dependencies.AddFactory(builder.Build());

            return(dependencies);
        }
コード例 #5
0
ファイル: SettingsInstaller.cs プロジェクト: teoadal/velo
        public static DependencyCollection AddSettings(this DependencyCollection dependencies)
        {
            dependencies
            .AddFactory <ISettingsProvider, SettingsProvider>(factory => factory
                                                              .CreateIf <NullSettingsProvider>(engine => !engine.Contains(typeof(ISettingsSource)))
                                                              .Lifetime(DependencyLifetime.Singleton))
            .AddFactory(new SettingsFactory())
            .EnsureJsonEnabled();

            return(dependencies);
        }
コード例 #6
0
ファイル: ECSInstaller.cs プロジェクト: teoadal/velo
        public static DependencyCollection AddECS(this DependencyCollection dependencies)
        {
            dependencies
            .AddSingleton <IEntityState, EntityState>();

            //actors
            dependencies
            .AddFactory(new FilterFactory <IActorContext>(typeof(IActorFilter)))
            .AddFactory(new GroupFactory <IActorContext>(typeof(IActorGroup)))
            .AddFactory(new SingleFactory <IActorContext>(typeof(SingleActor <>)))
            .AddInstance <IActorContext>(new ActorContext())
            .AddSingleton <IActorFactory, ActorFactory>();

            // assets
            dependencies
            .AddFactory(new FilterFactory <IAssetContext>(typeof(IAssetFilter)))
            .AddFactory(new GroupFactory <IAssetContext>(typeof(IAssetGroup)))
            .AddFactory(new SingleFactory <IAssetContext>(typeof(SingleAsset <>)))
            .AddSingleton <IAssetContext, AssetContext>()
            .AddSingleton <AssetFactory>();

            // components
            dependencies
            .AddSingleton <IComponentFactory, ComponentFactory>();

            // systems
            dependencies
            .AddFactory <ISystemService, SystemService>(systemService => systemService.DependedLifetime())
            .AddFactory(new SystemPipelineFactory());

            // source
            dependencies
            .AddInstance(new SourceDescriptions())
            .AddSingleton(typeof(IEntitySourceContext <>), typeof(EntitySourceContext <>))
            .EnsureJsonEnabled();

            return(dependencies);
        }
コード例 #7
0
        public static DependencyCollection AddSingleton(this DependencyCollection dependencies, Type implementation)
        {
            if (implementation.IsGenericTypeDefinition)
            {
                var factory = new GenericFactory(implementation, implementation, DependencyLifetime.Singleton);
                dependencies.AddFactory(factory);
            }
            else
            {
                dependencies.AddDependency(implementation, implementation, DependencyLifetime.Singleton);
            }

            return(dependencies);
        }