public static DependencyCollection AddHttpHandler <THandler>(this DependencyCollection dependencies, DependencyLifetime lifetime = DependencyLifetime.Singleton) where THandler : class, IHttpRequestHandler { dependencies.AddDependency(Typeof <IHttpRequestHandler> .Raw, typeof(THandler), lifetime); return(dependencies); }
public static DependencyCollection AddJsonConverter <TConverter>(this DependencyCollection dependencies) where TConverter : class, IJsonConverter { dependencies.AddDependency(ConverterContracts, typeof(TConverter), DependencyLifetime.Singleton); return(dependencies); }
public static DependencyCollection AddSingleton( this DependencyCollection dependencies, Type contract, Type implementation) { return(dependencies.AddDependency(contract, implementation, DependencyLifetime.Singleton)); }
public static DependencyCollection AddTransient( this DependencyCollection dependencies, Type contract, Type implementation) { return(dependencies.AddDependency(contract, implementation, DependencyLifetime.Transient)); }
public static DependencyCollection AddScoped <TContract, TImplementation>(this DependencyCollection dependencies) where TImplementation : TContract { var contract = Typeof <TContract> .Raw; var implementation = typeof(TImplementation); return(dependencies.AddDependency(contract, implementation, DependencyLifetime.Scoped)); }
public static DependencyCollection AddHttpHandler(this DependencyCollection dependencies, Func <IServiceProvider, IHttpRequestHandler> builder, DependencyLifetime lifetime = DependencyLifetime.Singleton) { var contracts = new[] { typeof(IHttpRequestHandler) }; dependencies.AddDependency(contracts, builder, lifetime); return(dependencies); }
public static DependencyCollection AddTransient <TContract>( this DependencyCollection dependencies, Func <IServiceProvider, TContract> builder) where TContract : class { var contracts = new[] { typeof(TContract) }; return(dependencies.AddDependency(contracts, builder, DependencyLifetime.Transient)); }
public static DependencyCollection AddMetricsCounter <TSender>(this DependencyCollection dependencies, Func <IServiceProvider, ICounter <TSender> > builder) { var contracts = new[] { typeof(ICounter), typeof(ICounter <TSender>) }; dependencies.AddDependency(contracts, builder, DependencyLifetime.Singleton); return(dependencies); }
public static DependencyCollection AddLogWriter <TWriter>(this DependencyCollection dependencies) where TWriter : ILogWriter { var implementation = Typeof <TWriter> .Raw; var contracts = new[] { Typeof <ILogWriter> .Raw, implementation }; dependencies.AddDependency(contracts, implementation, DependencyLifetime.Singleton); return(dependencies); }
public static DependencyCollection AddJsonSettings(this DependencyCollection dependencies, Func <IServiceProvider, string> fileNameBuilder, bool required = false) { dependencies.AddDependency( SettingsSourceContract, provider => new JsonFileSource(fileNameBuilder(provider), required), DependencyLifetime.Singleton); return(dependencies); }
public static DependencyCollection AddAssets( this DependencyCollection dependencies, Func <IServiceProvider, IEntitySource <Asset> > sourceBuilder) { if (sourceBuilder == null) { throw Error.Null(nameof(sourceBuilder)); } dependencies.AddDependency(AssetSourceContracts, sourceBuilder, DependencyLifetime.Singleton); 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); }
public static DependencyCollection AddSystem <TSystem>( this DependencyCollection dependencies, DependencyLifetime lifetime = DependencyLifetime.Singleton) { var implementation = typeof(TSystem); if (!ECSUtils.TryGetImplementedSystemInterfaces(implementation, out var contracts)) { throw Error.InvalidOperation( $"Type '{ReflectionUtils.GetName<TSystem>()}' isn't implemented system interfaces"); } dependencies.AddDependency(contracts, implementation, lifetime); return(dependencies); }
public static DependencyCollection AddAssets(this DependencyCollection dependencies, string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { throw Error.Null(nameof(filePath)); } dependencies.AddDependency(AssetSourceContracts, provider => new JsonFileSource <Asset>( provider.GetRequired <IConvertersCollection>(), provider.GetRequired <SourceDescriptions>(), filePath), DependencyLifetime.Singleton); return(dependencies); }
public static DependencyCollection AddAssets(this DependencyCollection dependencies, Stream stream) { if (stream == null) { throw Error.Null(nameof(stream)); } dependencies.AddDependency(AssetSourceContracts, provider => new JsonStreamSource <Asset>( provider.GetRequired <IConvertersCollection>(), provider.GetRequired <SourceDescriptions>(), stream), DependencyLifetime.Singleton); return(dependencies); }
private static bool AddDependencies( DependencyCollection dependencies, Type implementation, Type[] genericInterfaces, DependencyLifetime lifetime) { var contracts = ReflectionUtils.GetGenericInterfaceImplementations(implementation, genericInterfaces); if (contracts.Length == 0) { return(false); } contracts.Add(implementation); dependencies.AddDependency(contracts.ToArray(), implementation, lifetime); return(true); }
public static DependencyCollection AddTransient <TImplementation>(this DependencyCollection dependencies) { var implementation = Typeof <TImplementation> .Raw; return(dependencies.AddDependency(implementation, implementation, DependencyLifetime.Transient)); }
public static DependencyCollection AddSingleton <TImplementation>(this DependencyCollection dependencies) { var implementation = Typeof <TImplementation> .Raw; return(dependencies.AddDependency(implementation, implementation, DependencyLifetime.Singleton)); }
public static DependencyCollection AddScoped( this DependencyCollection dependencies, Type implementation) { return(dependencies.AddDependency(implementation, implementation, DependencyLifetime.Scoped)); }