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); }
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); }
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); }
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); }
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); }
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); }
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); }