Skip to content

Latest commit

 

History

History
60 lines (48 loc) · 1.84 KB

README.md

File metadata and controls

60 lines (48 loc) · 1.84 KB

Bulletin

Build Status Nuget

Bulletin is an in-progress library that simplifies file storage and processing for Dotnet Core projects using ASP.NET and Entity Framework Core.

Getting Started

First, you'll need to update your EF Database context to support Bulletin's Attachment model.

using Bulletin.EFCore;
using Bulletin.Models;

class MyDatabaseContext : IBulletinDbContext {
    
    public DbSet<Attachment> Attachments { get; set; }
    
    protected override void OnModelCreating(ModelBuilder modelBuilder) {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfiguration(new AttachmentEntityTypeConfiguration());
    }
}

Next, configure ASP.NET application startup with Bulletin.

using Bulletin;
using Bulletin.AspNetCore;
using Bulletin.Storage.File;
...
public class Startup {

    public void ConfigureServices(IServiceCollection services)
        services.AddBulletin<MyDatabaseContext>(b => {
            b.AddBoard(
                "images",
                new FileStorage(
                    new FileStorageOptions("./tmp/storage")
                )
            )
        })
    }
}

Bulletin will setup a service provider for easy access to storage boards.

class MyController {
    private readonly IBulletinBoard _imagesBoard;
    
    public MyController(IBulletin bulletin) {
        _imagesBoard = bulletin.GetBoard("images");
    }

    [HttpPost()]
    public Task<Attachment> UploadImage(IFormFile file) {
        return await _imagesBoard.AttachAsync(file.FileName, file.OpenReadStream());
    }
}