ContentAccess, CreateContainer

This commit is contained in:
2022-05-24 09:19:57 +02:00
parent 4ac99480fa
commit 60ab7f94ea
12 changed files with 209 additions and 62 deletions

View File

@@ -0,0 +1,23 @@
using FileTime.Core.ContentAccess;
using FileTime.Core.Models;
namespace FileTime.Providers.Local;
public class LocalItemCreator : ItemCreatorBase<ILocalContentProvider>
{
public override Task CreateContainerAsync(ILocalContentProvider contentProvider, FullName fullName)
{
var path = contentProvider.GetNativePath(fullName).Path;
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return Task.CompletedTask;
}
public override async Task CreateElementAsync(ILocalContentProvider contentProvider, FullName fullName)
{
var path = contentProvider.GetNativePath(fullName).Path;
await using (File.Create(path))
{
}
}
}

View File

@@ -1,6 +1,6 @@
using FileTime.Core.ContentAccess;
using FileTime.Core.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace FileTime.Providers.Local;
@@ -8,8 +8,10 @@ public static class Startup
{
public static IServiceCollection AddLocalServices(this IServiceCollection serviceCollection)
{
return serviceCollection
.AddSingleton<ILocalContentProvider, LocalContentProvider>()
.AddSingleton<IContentProvider, ILocalContentProvider>(sp => sp.GetRequiredService<ILocalContentProvider>());
serviceCollection.TryAddSingleton<ILocalContentProvider, LocalContentProvider>();
serviceCollection.TryAddSingleton<IContentProvider>(sp => sp.GetRequiredService<ILocalContentProvider>());
serviceCollection.TryAddSingleton<IItemCreator<ILocalContentProvider>, LocalItemCreator>();
serviceCollection.TryAddSingleton<IItemCreator<LocalContentProvider>>(sp => sp.GetRequiredService<IItemCreator<ILocalContentProvider>>());
return serviceCollection;
}
}