201 热度

Running .NET Core Applications as a Linux Service

In this article, we are going to learn how to run a .NET application as a Linux service. Linux operating system contains a service manager called Systemd. The Systemd acts as an initialization system and controls what programs and services run when the system boots up. While working with Linux, we can make use of Systemd to manage our services.

收录时间: 2022-07-28
分类: .NET Core
贡献者: Rector
169 热度

Adding content negotiation to minimal APIs with Carter

In my previous post I described how to return XML from a minimal API endpoint. In this post I look at an alternative approach, using the open source library, Carter.

收录时间: 2022-07-13
分类: .NET Core
贡献者: Rector
195 热度

Running .NET Core Applications as a Windows Service

In this article, we are going to learn how to create a .NET Core Worker Service and run it as a Windows Service.

收录时间: 2022-07-01
分类: .NET Core
贡献者: Rector
341 热度

Using MySQL in a Docker container with EF Core

Recently I’ve been asked for a sample using EF Core with MySQL. When using EF Core I’m using Micorosft SQL Server or Azure Cosmos DB – and you have many code samples for EF Core in my book Professional C# and .NET, 2021 Edition. To demonstrate using EF Core I took one of the existing samples and changed the SQL Server provider to a MySQL provider. For not needing to install MySQL on my system, I’m using a Docker image as you can read here...

收录时间: 2022-05-18
分类: .NET Core
贡献者: Rector
459 热度

.NET 4.x app running in a container using Docker

So this blog post comes from doing some work recently to containerize a .Net 4.8 project that needs to run on a Windows container. I wrote about Windows containers already so this is going to be some other tips to help someone who may have run into the same issues I did.

收录时间: 2022-03-12
分类: .NET Core
贡献者: Rector
285 热度

Create a RESTful API with .NET Core and MongoDB

If you've been keeping up with my development content, you'll remember that I recently wrote Build Your First .NET Core Application with MongoDB Atlas, which focused on building a console application that integrated with MongoDB. While there is a fit for MongoDB in console applications, many developers are going to find it more valuable in web applications. In this tutorial, we're going to expand upon the previous and create a RESTful API with endpoints that perform basic create, read, update, and delete (CRUD) operations against MongoDB Atlas.

收录时间: 2022-02-09
分类: .NET Core
贡献者: Rector
AD 友情赞助
514 热度

.Net Core——用SignalR撸个游戏

之前开内部培训,说到实时web应用这一块讲到了SignalR,我说找时间用它做个游戏玩玩,后面时间紧张就一直没安排。这两天闲了又想起这个事,考虑后决定用2天时间写个斗D主,安排了前端同学写客户端,我写游戏逻辑和服务。这个项目难度并不高,但是游戏逻辑还是挺绕的,联调过程中也发现解决了很多小问题。来园子里整理一篇文章,记录一下。基础的介绍就免了,毕竟官网跟着走两圈啥都懂了。没基础的可以戳这里,是我之前写的一篇SignalR基础介绍,带有一个极简聊天室。tips:文章结尾有开源地址,游戏数据都是本地的,改下IP运行起来就可以玩了。直接上干货,首先是数据模型...

收录时间: 2022-01-04
分类: .NET Core
贡献者: Rector
629 热度

一行代码完成定时任务调度,基于Quartz的UI可视化操作组件 GZY.Quartz.MUI

之前发布过第一个版本,有兴趣的可以去看看:NET Core 基于Quartz的UI可视化操作组件 GZY.Quartz.MUI 简介GitHub开源地址:l2999019/GZY.Quartz.MUI: 基于Quartz的轻量级,注入化的UI组件 (github.com) (欢迎点Start收藏~)总而言之,这个组件主要想做的就是:像swaggerUI一样,项目入侵量小,仅需要在Startup中注入的UI组件目前完成了第二个版本,1.增加本地json持久化调度任务,无需数据库2.增加直接调用本地类方法,无需通过WebAPI接口.本篇主要是介绍一下这两个新增的功能. 正文一.增加本地json...

收录时间: 2021-12-30
分类: .NET Core
贡献者: Rector
454 热度

浅析.netcore中的Configuration

不管是.net还是.netcore项目,我们都少不了要读取配置文件,在.net中项目,配置一般就存放在web.config中,但是在.netcore中我们新建的项目根本就看不到web.config,取而代之的是appsetting.json。新建一个webapi项目,可以在startup中看到一个IConfiguration,通过框架自带的IOC使用构造函数进行实例化,在IConfiguration中我们发现直接就可以读取到appsetting.json中的配置项了,如果在控制器中需要读取配置,也是直接通过构造函数就可以实例化IConfiguration对象进行配置的读取。下面我们试一下运行的...

收录时间: 2021-12-27
分类: .NET Core
贡献者: Rector
393 热度

Optimistic Concurrency in an HTTP API with ETags & Hypermedia

How do you implement optimistic concurrency in an HTTP API? There are a couple of different ways, regardless of what datastore you’re using in the backend. You can leverage the ETag header in the HTTP Response to return a “version” of the resource that was accessed. When a client then needs to perform some operation on the resource, they send an If-Match header apart of the request with the value being the result of ETag from the initial GET request. Another option is to leverage hypermedia by returning URIs for actions relevant to a resource that include the version apart of the URI. This enables concurrency to be completely transparent and does not require any knowledge from the client.

收录时间: 2021-12-16
分类: .NET Core
贡献者: Rector
368 热度

Finding Async Method Calls Missing Await

I’ve run into this issue not only when migrating legacy projects to use async/await in C# .NET, but even just day to day on greenfields projects. The issue I’m talking about involves code that looks like so

收录时间: 2021-12-13
分类: .NET Core
贡献者: Rector
332 热度

Custom JSON Serialisation with System.Text.Json Converters

In this post, I want to cover one of the more complex concepts I’ve had to handle regarding serialisation; aggregations.

收录时间: 2021-12-13
分类: .NET Core
贡献者: Rector
348 热度

YARP+AgileConfig 5分钟实现一个支持配置热更新的代理网关

YARP 是微软开源的一个反向代理项目,英文名叫 Yet Another Reverse Proxy 。所谓反向代理最有名的那就是 nginx 了,没错 YARP 也可以用来完成 nginx 的大部分功能,比如根据不一样的域名代理到不一样的后端服务上。既然它可以做反向代理,那么其实也就可以做服务网关了,类似 Ocelot ,当然缺少部分功能,比如限流降级等。Anyway ,今天先来体验一下。运行 YARPYARP 使用起来非常简单,它只是一个类库而已。我们新建一个 ASP.NET Core 的空网站。然后使用 nuget 安装 Yarp.ReverseProxy 。Install-Packag...

收录时间: 2021-12-12
分类: .NET Core
贡献者: Rector
510 热度

An optimization story:–27% runtime costs for 8 lines of code

I give a lot of talks about performance and in those talks, I tend to emphasize the architectural impact of your choices. There is a huge tendency to focus on micro optimizations to get the performance you need, even though you can usually get orders of magnitude higher performance by making architectural changes.

收录时间: 2021-12-07
分类: .NET Core
贡献者: Rector
425 热度

Upgrading a .NET 5 "Startup-based" app to .NET 6 Exploring .NET Core 6 - Part 12

In this short post I tackle a question I have received several times—"how can I update an ASP.NET Core 5 app that uses Startup to .NET 6's minimal hosting APIs"?

收录时间: 2021-12-01
分类: .NET Core
贡献者: Rector
AD 友情赞助
420 热度

.NET Core中的鉴权授权正确方式(.NET5)

前后端分离的站点一般都会用jwt或IdentityServer4之类的生成token的方式进行登录鉴权。这里要说的是小项目没有做前后端分离的时站点登录授权的正确方式。二、传统的授权方式这里说一下传统授权方式,传统授权方式用session或cookies来完成。1.在请求某个Action之前去做校验,验证当前操作者是否登录过,登录过就有权限2.如果没有权限就跳转到登录页中去3.传统登录授权用的AOP-Filter:ActionFilter。

收录时间: 2021-11-25
分类: .NET Core
贡献者: Rector
461 热度

[CallerArgumentExpression] and throw helpers: Exploring .NET Core 6 - Part 11

In this post I describe a new feature in C# 10, the [CallerArgumentExpression] attribute, how it can be used to create "throw helpers", and the addition of a throw helper to ArgumentNullException.

收录时间: 2021-11-24
分类: .NET Core
贡献者: Rector
384 热度

Avoid Using Exceptions to Determine API Status Codes and Responses

It's typical for API endpoints to call application or domain services. In the case of success, the API can simply return Ok and the result of the service call. But for non-success cases, should you use exceptions to communicate from the service to the endpoint, so that it can return an appropriate status code and response? Assuming you read the title of this article, you probably already know the answer I'm going to give. But first let's look at a (bad) example. Consider the following method found in a service that will be called by an API endpoint (controller action)

收录时间: 2021-11-17
分类: .NET Core
贡献者: Rector
517 热度

Source generator updates: incremental generators: Exploring .NET Core 6 - Part 9

In the previous post, I described the LoggerMessage source generator that can give performance benefits without the boilerplate. In this post I look at the updates to the source generator API in .NET 6, why the changes were made, and how to update your source generators to use them.

收录时间: 2021-11-10
分类: .NET Core
贡献者: Rector
426 热度

How to use JSONPatch in .net core

REST API’s often require a PATCH method to partially update resources. A typical scenario for this would be when updating a survey questionnaire type workflow or even, as in the example I will demonstrate, updating a customers shopping cart in an e-commerce Microservice. As a customer updates their cart by adding, removing or editing products in the cart you’ll need to cater for a number of operations.

收录时间: 2021-11-10
分类: .NET Core
贡献者: Rector
AD 友情赞助