public static IServiceCollection AddLocalFsStorage <TStorageInfo>(this IServiceCollection services, string name, LocalFsStorageConfiguration storageConfiguration) where TStorageInfo : LocalStorageInfo { var infoType = typeof(TStorageInfo); var constructorInfo = infoType.GetConstructor(new[] { typeof(string), typeof(string) }); if (constructorInfo == null) { throw new InvalidOperationException("Can't find constructor with 2 string input params"); } var storageInfo = (TStorageInfo)constructorInfo.Invoke(new[] { name, storageConfiguration.Path }); services.AddSingleton <TStorageInfo>(storageInfo); services.AddSingleton <IStorage <TStorageInfo>, LocalStorage <TStorageInfo> >(); return(services); }
public static IServiceCollection AddLocalFsStorage(this IServiceCollection services, LocalFsStorageConfiguration storageConfiguration) { var storageInfo = new LocalStorageInfo(storageConfiguration.Path); services.AddSingleton <LocalStorageInfo>(storageInfo); services.AddSingleton <IStorage <LocalStorageInfo>, LocalStorage <LocalStorageInfo> >(); return(services); }