A ready-to-use template for ASP.NET Core with repositories, services, models mapping, DI and StyleCop warnings fixed.
You can install this template using NuGet:
dotnet new --install AspNetCoreTemplate
dotnet new aspnet-core-template -n YourProjectName
AspNetCoreTemplate.Common contains common things for the project solution. For example:
This solution folder contains three subfolders:
- AspNetCoreTemplate.Data.Common
- AspNetCoreTemplate.Data.Models
- AspNetCoreTemplate.Data
AspNetCoreTemplate.Data.Common.Models provides abstract generics classes and interfaces, which holds information about our entities. For example when the object is Created, Modified, Deleted or IsDeleted. It contains a property for the primary key as well.
AspNetCoreTemplate.Data.Common.Repositories provides two interfaces IDeletableEntityRepository and IRepository, which are part of the repository pattern.
AspNetCoreTemplate.Data.Models contains ApplicationUser and ApplicationRole classes, which inherits IdentityRole and IdentityUsers.
AspNetCoreTemplate.Data contains DbContext, Migrations and Configuraitons for the EF Core.There is Seeding and Repository functionality as well.
This solution folder contains four subfolders:
- AspNetCoreTemplate.Services.Data
- AspNetCoreTemplate.Services.Mapping
- AspNetCoreTemplate.Services.Messaging
- AspNetCoreTemplate.Services
AspNetCoreTemplate.Services.Data wil contains service layer logic.
AspNetCoreTemplate.Services.Mapping provides simplified functionlity for auto mapping. For example:
using Blog.Data.Models;
using Blog.Services.Mapping;
public class TagViewModel : IMapFrom<Tag>
{
public int Id { get; set; }
public string Name { get; set; }
}
Or if you have something specific:
using System;
using AutoMapper;
using Blog.Data.Models;
using Blog.Services.Mapping;
public class IndexPostViewModel : IMapFrom<Post>, IHaveCustomMappings
{
public int Id { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string ImageUrl { get; set; }
public DateTime CreatedOn { get; set; }
public void CreateMappings(IProfileExpression configuration)
{
configuration.CreateMap<Post, IndexPostViewModel>()
.ForMember(
source => source.Author,
destination => destination.MapFrom(member => member.ApplicationUser.UserName));
}
}
AspNetCoreTemplate.Services.Messaging a ready to use integration with SendGrid.
This solution folder contains three subfolders:
- AspNetCoreTemplate.Services.Data.Tests
- AspNetCoreTemplate.Web.Tests
- Sandbox
AspNetCoreTemplate.Services.Data.Tests holds unit tests for our service layer with ready setted up xUnit.
AspNetCoreTemplate.Web.Tests setted up Selenuim tests.
Sandbox can be used to test your logic.
This solution folder contains three subfolders:
- AspNetCoreTemplate.Web.Infrastructure
- AspNetCoreTemplate.Web.ViewModels
- AspNetCoreTemplate.Web
AspNetCoreTemplate.Web.Infrastructure contains functionality like Middlewares and Filters.
AspNetCoreTemplate.Web.ViewModels contains objects, which will be mapped from/to our entities and used in the front-end/back-end.
AspNetCoreTemplate.Web self explanatory.
If you are having problems, please let us know by raising a new issue.
This project is licensed with the MIT license.