mirror of https://github.com/abpframework/abp.git
6 changed files with 81 additions and 63 deletions
@ -1,9 +1,16 @@ |
|||
using Volo.Abp.Modularity; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BlobStoring |
|||
{ |
|||
public class AbpBlobStoringModule : AbpModule |
|||
{ |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddTransient( |
|||
typeof(IBlobContainer<>), |
|||
typeof(TypedBlobContainerWrapper<>) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System.Threading; |
|||
|
|||
namespace Volo.Abp.BlobStoring |
|||
{ |
|||
public interface IBlobContainerFactory |
|||
{ |
|||
/// <summary>
|
|||
/// Gets a named container.
|
|||
/// </summary>
|
|||
/// <param name="name">The name of the container</param>
|
|||
/// <param name="cancellationToken">Cancellation token</param>
|
|||
/// <returns>
|
|||
/// The container object.
|
|||
/// </returns>
|
|||
IBlobContainer Get( |
|||
string name, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.BlobStoring |
|||
{ |
|||
public interface IBlobContainerManager |
|||
{ |
|||
/// <summary>
|
|||
/// Gets a named container.
|
|||
/// </summary>
|
|||
/// <param name="name">The name of the container</param>
|
|||
/// <param name="cancellationToken">Cancellation token</param>
|
|||
/// <returns>
|
|||
/// The container object.
|
|||
/// </returns>
|
|||
Task<IBlobContainer> GetAsync( |
|||
string name, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
|
|||
/// <summary>
|
|||
/// Deletes a container.
|
|||
/// </summary>
|
|||
/// <param name="name">The name of the container</param>
|
|||
/// <param name="cancellationToken">Cancellation token</param>
|
|||
/// <returns>
|
|||
/// Returns true if actually deleted the container.
|
|||
/// Returns false if the container with the given <paramref name="name"/> was not exists.
|
|||
/// </returns>
|
|||
Task<bool> DeleteAsync( |
|||
string name, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using System.IO; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.BlobStoring |
|||
{ |
|||
public class TypedBlobContainerWrapper<TContainer> : IBlobContainer<TContainer> |
|||
where TContainer: class |
|||
{ |
|||
private readonly IBlobContainer _container; |
|||
|
|||
public TypedBlobContainerWrapper(IBlobContainerFactory blobContainerFactory) |
|||
{ |
|||
_container = blobContainerFactory.Get<TContainer>(); |
|||
} |
|||
|
|||
public Task SaveAsync(string name, Stream stream, bool overrideExisting = false, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _container.SaveAsync(name, stream, overrideExisting, cancellationToken); |
|||
} |
|||
|
|||
public Task<bool> DeleteAsync(string name, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _container.DeleteAsync(name, cancellationToken); |
|||
} |
|||
|
|||
public Task<bool> ExistsAsync(string name, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _container.ExistsAsync(name, cancellationToken); |
|||
} |
|||
|
|||
public Task<Stream> GetAsync(string name, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _container.GetAsync(name, cancellationToken); |
|||
} |
|||
|
|||
public Task<Stream> GetOrNullAsync(string name, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _container.GetOrNullAsync(name, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue