GithubHelp home page GithubHelp logo

atlasoutdoor / dotnettemplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cieranaverell/dotnettemplate

0.0 0.0 0.0 1.67 MB

Template DotNetCore Web Solution

C# 67.07% HTML 30.12% CSS 2.34% JavaScript 0.48%

dotnettemplate's Introduction

DotNet 6 Clean Architecture MVC Solution

This .NET project Template demonstrates concept of separation of concerns (SOC) and is a simple implementation of the Clean Architecture. When installed and used to create a new project, all references to Template will be replaced with the name of your project.

Core Project

The Core project contains all domain entities and service layer interfaces and has no dependencies.

Password hashing functionality added via the Template.Core.Security.Hasher class. This is used in the Data project UserService to hash the user password before storing in database.

Data Project

The Data project encapsulates all data related concerns. It provides an implementation of Template.Core.Services.IUserService using EntityFramework to handle data storage/retrieval. It defaults to using Sqlite for portability across platforms.

The Service is the only element exposed from this project and consumers of this project simply need reference it to access its functionalty.

Test Project

The Test project references the Core and Data projects and should implement unit tests to test any service implementations created in the Data project. A template test is provided for implementation of IUserService and the tests should be extended to fully exercise the functionality of your Service.

Web Project

The Web project uses the MVC pattern to implement a web application. It references the Core and Data projects and uses the exposed services and models to access data management functionality. This allows the Web project to be completely independent of the persistence framework used in the Data project.

Identity

The project provides extension methods to enable:

  1. User Identity using cookie authentication is enabled without using the boilerplate template used in the standard web projects (mvc,web). This allows the developer to gain a better appreciation of how Identity is implemented. The data project implements a User model and the UserService provides user management functionality such as Authenticate, Register, Change Password, Update Profile etc.

The Web project implements a UserController with actions for Login/Register/NotAuthorized/NotAuthenticated etc. The AuthBuilder helper class defined in Template.Web.Helpers provides a BuildClaimsPrinciple method to build a set of user claims for User Login action when using cookie authentication and this can be modified to amend the claims added to the cookie.

To enable cookie Authentication the following statement is included in Program.cs.

builder.Services.AddCookieAuthentication();

Then Authentication/Authorisation are then turned on in the Application via the following statements in Program.cs

app.UseAuthentication();
app.UseAuthorization();

Additional Functionality

  1. Any Controller that inherits from the Web project BaseController, can utilise:

    a. The Alert functionality. Alerts can be used to display alert messages following controller actions. Review the UserController for an example using alerts.

    Alert("The User Was Registered Successfully", AlertType.info);

    b. Authentication function helper methods

    • GetSignedInUserId() - returns Id of current logged in user or 0 if not logged in
    • IsAuthenticated() - returns a boolean to indicate if user is logged in
  2. Two custom TagHelpers are included that provide

    a. Authentication and authorisation Tags

    • <p asp-authorized>Only displayed if the user is authenticated</p>

    • <p asp-roles="Admin,Manager">Only displayed if the user has one of specified roles</p>

    Note: to enable these tag helpers Program.cs needs following service added to DI container builder.Services.AddHttpContextAccessor();

    b. Conditional Display Tag

    • <p asp-condtion="@some_boolean_expression">Only displayed if the condition is true</p>

Install Template

To install this solution as a template (template name is termonclean)

  1. Download current version of the template

    $ git clone https://github.com/termon/DotNetTemplate.git

  2. Install the template so it can be used by dotnet new command. Use the path (i.e the directory location)to the cloned template directory without trailing '/'

Linux/macOS

$ dotnet new -i /path/DotNetTemplate

Windows

c: dotnet new -i c:\path\DotNetTemplate

  1. Once installed you can create a new project using this template

    dotnet new termonclean -o SolutionName

dotnettemplate's People

Contributors

termon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.