ASP.NET Core 12 samples

In today’s post, I’d like to present a dozen of minimalistic samples that you can make use of within ASP.NET Core application. Starting from simple things like options, through middleware, databases and even Nginx or Docker. These samples are part of the upcoming event “Thursday with .NET” that I’ll be part of on Thursday 20.04.2017.


 

Make sure you execute dotnet restore first and then dotnet run to start the particular application. If the example is using an external resource like a database, ensure that you have it installed and running before starting the app.

1. Options

Let’s warm up with the options provider. You can easily create a so-called XyzOptions class and bind it to the configuration defined in the appsettings.json file and use it in your application simply by injecting IOptions instance.

2. Middleware

You can extend the HTTP request pipeline by adding your own middleware into the overall flow. If you ever used a framework like NodeJS and wanted to have the same possibility of providing your own code in order to e.g. validate or process the incoming request, you can do it in ASP.NET Core as well.

3. Filters

In need of the custom exception handler? Need to log the incoming requests or validate them? These and much more can be achieved by using filters, simply by creating a new attribute and using them on top of your MVC controllers.

4. Autofac

Dependency Injection and IoC container are built-in to the framework, however, you can still use your favorite libraries like Autofac if you feel like you need something more powerful in terms of dependency inversion principle.

5. Tests

We are all aware how to write the good unit tests, correct? But what about the integration (end-to-end) tests? For sure, you can expose the running instance of your API and perform the HTTP requests e.g. via HttpClient instance. Yet, there’s a better way and you can do such tests in memory thanks to TestHost library.

6. SQL Server

Did you know that you can run SQL Server on Linux? Anyway, you can connect to the SQL Server instance via .NET Core e.g. by using Entity Framework Core library, however, I do prefer a more lightweight solution, thus the provided example makes use of the Dapper.

7. MongoDB

Do you like NoSQL databases like I do? You can use the MongoDB Driver and connect to the MongoDB databases from the .NET Core applications.

8. Redis

Powerful caching can be surely done by Redis. And you can connect to the Redis server thanks to the developers from StackExchange who did create such a great library.

9. RabbitMQ

Using service bus is one of the most common ways when it comes to creating a distributed system. RabbitMQ is one of those and you can make use of it either by adding the official library or the RawRabbit which I like due to its abstractions and ease of use.

10. Nancy

Nancy is an amazing framework for building the HTTP API. I like it very much and I was very happy when I found out that it’s compatible with the ASP.NET Core framework.

11. Docker

Containerized applications and containers, in general, are industry standard nowadays. You can easily make use of the Docker and build your ASP.NET Core applications on top of that.

12. Nginx

Thanks to the Kestrel HTTP Server you’re no longer forced to use the IIS. For example, you choose Apache or Nginx and host your .NET Core applications also on the Linux servers.

As mentioned above, all of the examples can be found and downloaded from the GitHub.

2 Comments ASP.NET Core 12 samples

  1. Pingback: ASP.NET Core 12 samples - How to Code .NET

  2. Pingback: Dew Drop - April 17, 2017 (#2459) - Morning Dew

Leave A Comment

Your email address will not be published. Required fields are marked *