DerekJi / Boostart.NET

.NET Core RESTful API Project Template for CRUD applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boostart.NET

ASP.NET Core RESTful API Project Template for CRUD applications


Key Features

  • Essential Database Operations (CRUD) in BaseDataService & BaseController.
  • Dependency Injections
  • Swagger configured
  • Automatic Request Logging (NLog)

HOW TO: Run this demo


HOW TO: Add New Controller(s)

With Boostart.NET, you could have a new fully functional controller providing CRUD endpoints within 5 minutes.

Now, let's suppose we are going to setup a new set of endpoints for the new table: Departments.

Here are all the things you have to do:

  • Step #1. Define the database entity under Database.Entity/Entities. It looks like:
    public class Department: BaseEntity
    {
        [MaxLength(255)]
        public string DepartmentName{ get; set; }
    
        [MaxLength(255)]
        public string Address { get; set; }
    }

    NOTE:

    • the new entity MUST inherit from BaseEntity
  • Step #2. Run any dotnet ef command you'd like to update the database;
  • Step #3. Create the new data service class and interface
    /// IDepartmentsDataService.cs
    public interface IUsersDataService : IBaseDataService<User>
    {
    }
    
    /// DepartmentsDataService.cs
    public class DepartmentsDataService : BaseDataService<Department>, IDepartmentsDataService
    {
        public DepartmentsDataService(
            IHttpContextAccessor httpContextAccessor,
            IBaseRepository<User> repos
            ) : base(httpContextAccessor, repos)
        {
        }
    }
  • Step #4. Create the controller
    [Route("api/[controller]")]
    [ApiController]
    public class DepartmentsController : BaseController<Department>
    {
        public DepartmentsController(
            ILogger<ILogActionFilter> logger, 
            IDepartmentsDataService dataService)
            : base(logger, dataService)
        {
        }
    
    }
  • Done!

As you can see, what you did is just create

  • new entity from BaseEntity
  • new data service from BaseDataService
  • new controller from BaseController

That's it!

You don't have to do too many copy & pastes, so you could just focus on the relationships between the entities and business logic.

Enjoy! :)

About

.NET Core RESTful API Project Template for CRUD applications

License:GNU General Public License v3.0


Languages

Language:C# 98.4%Language:Dockerfile 1.6%