133 热度

.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
120 热度

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
212 热度

.Net Core——用SignalR撸个游戏

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

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

一行代码完成定时任务调度,基于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
227 热度

浅析.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
207 热度

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
AD 友情赞助
209 热度

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
178 热度

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
179 热度

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
267 热度

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
220 热度

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
241 热度

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

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

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

[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
234 热度

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
262 热度

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
AD 友情赞助
257 热度

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
342 热度

Improving logging performance with source generators: Exploring .NET Core 6 - Part 8

In this post I look at the new LoggerMessage source generator, showing how and when to use it. I start by showing the existing ways to use ILogger, pitfalls to watch out for, and approaches to improve performance. I then show how the source generator simplifies this. We look at the code it generates, and do some simple benchmarks to see the performance benefits this brings.

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

Build client web assets for your Razor Class Library

In this post we’ll show you how to integrate npm and webpack into the build process for your Razor Class Library. For folks who want a solution that just works, we’ll look at the new experimental Microsoft.AspNetCore.ClientAssets package that handles this integration for you automatically provided you have the right tools installed. We’ll also walk through all the details of how to set this up using MSBuild for folks that want to be able to control and customize the process. While the focus of this post is npm and webpack, the solution that we provide here can easily be adapted to other tools like yarn, rollup, etc.

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

.Net Core中使用ElasticSearch(一)

在官网下载Es,注意版本号,不同大版本号之间差异很大。我安装的是7.14.0版本1.1 安装成服务cmd 进入bin目录下执行elasticsearch-service.bat install1.2 安装插件ik分词器,分词器的版本和ES版本需要一致elasticsearch-plugin.bat install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.14.0/elasticsearch-analysis-ik-7.14.0.zip1.3 配置账号密码修改config目录下面的...

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

Analyzers for ASP.NET Core in .NET 6: Exploring .NET Core 6 - Part 7

Analyzers have been built into the C# compiler for some time now. Anyone can write their own analyzer, distribute it as a NuGet package, and hook into the compiler to find potential code issues. In this post I look at the changes to the existing ASP.NET Core analyzers in .NET 6, as well as the new ones added for the new minimal APIs. This post ended up a little long, so I've included shortcuts to each of the analyzers I describe in case you want to skip ahead...

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