public static void TryAddTransient <TService, TImplementation>(this ICoconaLiteServiceCollection services) where TImplementation : TService { if (services.All(x => x.ServiceType != typeof(TService))) { services.AddTransient <TService, TImplementation>(); } }
public static void TryAddTransient <TService, TImplementation>(this ICoconaLiteServiceCollection services, Func <IServiceProvider, TService> factory) where TImplementation : TService { if (services.All(x => x.ServiceType != typeof(TService))) { services.AddTransient <TService>(factory); } }
public static void AddJsonConfigurationService( this ICoconaLiteServiceCollection services, string jsonConfigurationPath) { string jsonConfigurationDirectory = Directory.GetParent(jsonConfigurationPath).FullName; if (!Directory.Exists(jsonConfigurationDirectory)) { Directory.CreateDirectory(jsonConfigurationDirectory); } var pfs = new PhysicalFileSystem(); var fileSystem = new SubFileSystem( pfs, pfs.ConvertPathFromInternal(jsonConfigurationDirectory), owned: true); services.AddTransient <IConfigurationService <ToolConfiguration> >( _ => new JsonConfigurationService( fileSystem, Path.GetFileName(jsonConfigurationPath))); }