Giter Site home page Giter Site logo

drwatson1 / aspnet-core-rest-service Goto Github PK

View Code? Open in Web Editor NEW
73.0 7.0 23.0 489 KB

VS2017/VS2019/2022 project template for ASP.Net 5/6 to create fully functional production ready RESTful services

License: MIT License

C# 100.00%
asp-net-core csharp vs2017 visual-studio project-template restful-api vs2019 vs2022 webapi

aspnet-core-rest-service's Introduction

ASP.Net REST API Service Template

The repository contains a ready to use preconfigured project template for MS Visual Studio 2017, 2019 and 2022 to create fully functional production-ready cross-platform RESTful services based on .Net 5.0/6.0.

Note 1. The current version does not support .Net Core 3.1. If you want to use it you can use the previous version 2.6.

Note 2. ASP.NET Core 3.0 has many breaking changes against version 2.2. If you want to use v2.2 or earlier, please, check out one of the previous releases, starting from version 1.3 or earlier.

Note 3. If you are looking for classic ASP.Net services with WebAPI2 and other stuff like that, please, check out a project ASP.Net WebApi2 Application with OWIN.

This template is intended to provide you an almost all that you need for creating RESTful services. The project doesn't contain any UI stuff, like React or Angular libraries, npm, Razor views, as well as any problem domain specific things like EnityFramework, some "right" or "neat" project structure or even a number of projects, each for the specific purpose (for example, service itself, domain logic, data access, testing and so on) as it does some other templates. There are too many areas where ASP.Net Core services can be used, so it can hardly be offered anything related to domain areas to fit all of these project types.

However, some things must be implemented or configured in almost each of the projects, regardless of the subject area. Among these things are dependency injection, exception handling, logging, and others. There are many libraries and solutions to address each of them, but it is impossible to choose a set that fits absolutely everyone. In this project, I have collected the solutions that I consider the most convenient and use them for years in almost each of my projects. I hope you like them too :). So, the project contains these the most important features, but is not limited to them:

  • CORS and preflight requests support
  • Autofac as a DI-container
  • AutoMapper
  • Serilog as a default preconfigured logger
  • Unhandled exceptions handling
  • Swagger for API documentation
  • Ability to use environment variables in configuration options and support for '.env' files to easy switching between different environments (thanks to DotNetEnv)
  • ... and some boilerplate code

Let me know, what do you think. Any suggestions and bug reports are very appreciated.

Getting Started

Using Visual Studio

  1. Install the extension from Visual Studio Marketplace or download and install the latest version from GitHub. Also, you can install it from Visual Studio. To do so click on "Tools/Extensions and Updates..." menu item, then select "Online/Visual Studio Marketplace/Templates" on the left pane, search for "ASP.Net Core RESTful Service Template," select it and click "Download" button. Please note! The latest version of the template is targeted to the .Net 6.0. If you need a template for the 3.1 or 2.x version use one of the previous versions of the template.
  2. Restart Visual Studio
  3. Click on "File/New Project..." menu item
  4. Select "APS.Net REST API Service" and click OK button.
  5. Select either "IIS Express" or "RestApi.Sevice1" mode and run a service
  6. Open a browser and navigate to http://localhost:5000/swagger to see an API documentation
  7. Play around with the API. Try to add a new product or update one

Using command line

  1. Install the template:
dotnet new -i DrWatson1.ProjectTemplate.RestAPI
  1. Create a project:
dotnet new rest-api -n RestApiService

It creates a new project "ASPNetCoreService" in the corresponding subfolder. Replace the "ASPNetCoreService" with a desired name.

  1. Run the project:
cd RestApiService
dotnet run
  1. Open a browser and navigate to http://localhost:5000/swagger to see an API documentation
  2. Play around with the API. Try to add a new product or update one

Visit project Wiki pages to learn more about the template.

Have fun and happy hacking!

Release Notes

Date Version Release Notes
2022-75-23 3.0

- BREAKING CHANGES: Drop support of .Net Core 3.1

- The template now uses .Net 6.0 by default

- Support of Visual Studio 2022

- All packages was updated to the latest versions

2021-05-03 2.6

- Support of .Net 5.0

- Add dotnet new custom template

2021-03-07 2.5

- Minor fixes

2021-02-27 2.4

- Improve logging

2021-02-23 2.3

- Load .env before Serilog initialization to make it possible to use environment variables in Serilog configuration options

- Catch and log unhandled exceptions

- Update NuGet packages to the latest versions

2020-08-14 2.2

- Allow Swagger to work behind a proxy

- Improve Application Settings with Options Pattern and Configuration Extensions

- Update NuGet packages to the latest versions

2020-01-22 2.1

- Fix deploying to IIS

- Fix publishing the service

2020-01-22 2.0

- Change target framework to .Net Core 3.1

- Add health check service

2020-01-21 1.3

- Update target framework to .Net Core 2.2

2019-08-22 1.2

- Project tags are added to make it simple to find this project template in a VS2019 project creation wizard

- Update NuGet packages to the latest versions

2019-04-03 1.1 - Support VS2019
2019-01-21 1.0 - Initial version

aspnet-core-rest-service's People

Contributors

drwatson1 avatar tsvx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnet-core-rest-service's Issues

.env-file don't work for logs

Problem: .env-file don't work for logs

Reason: .env file loaded after serilog read appsetting.config
So I can't write something like "path": "%MY_WAR%/Logs/ReferenceProject.log"

Also, please use uppercase in names of environment variables, AppData should be APPDATA

ILoggerProvider not working

ILogger provider is not properly configured and cannot be used

Sample code
public ProductsRepo(
ILogger logger,
ILoggerProvider loggerProvider
)
{
var logger2 = loggerProvider.CreateLogger("abc");
logger.LogCritical("ILOGGER LOG");
logger2.LogCritical("ILOGGERPROVIDER LOG");
}

Output
[FTL] ILOGGER LOG

Expected output
[FTL] ILOGGER LOG
[FTL] ILOGGERPROVIDER LOG

Authentication

Hey, Great stuff. Huge thanks. Do you intend to include authentication with JWT to the project structure someday?

Log DI container creation exceptions

For instance, the following approach would work in the Main() method:
Instead of CreateHostBuilder(args).Build().Run(); do

            Microsoft.Extensions.Logging.ILogger logger = null;
            try
            {
                var hostBuilder = CreateHostBuilder(args);
                var host = hostBuilder.Build();
                logger = (Microsoft.Extensions.Logging.ILogger)host.Services.GetService(typeof(Microsoft.Extensions.Logging.ILogger<Program>));
                host.Run();
            }
            catch (Exception ex)
            {
                logger?.LogCritical(ex, "Unhandled Exception, closing application.");
            }

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.