martin fowler_通过在David Fowler的GitHub上闲逛来了解.NET Core期货

martin fowler

martin fowler

A picture of David silently judging my code, but with love

David Fowler is the ASP.NET Core Architect (and an amazing highly technical public speaker) and I've learned a lot from watching him code. However, what's the best way for YOU to learn from folks like David if you can't sit on their shoulder? Why, look at their GitHub!

大卫·福勒(David Fowler)是ASP.NET核心架构师(也是一位非常出色的高科技演讲者),我从看他的代码中学到了很多东西。 但是,如果您不能坐在他们的肩膀上,那么向大卫这样的人学习的最佳方法是什么? 为什么,看看他们的GitHub!

Since .NET Core (and most of Microsoft) is not only open source but also developed in the open now on GitHub, we can actually watch folks in their day to day work as they commit code to projects like the C# compiler, .NET Core, and ASP.NET Core.

由于.NET Core(以及Microsoft的大多数公司)不仅是开源的,而且还在GitHub上公开开发,因此我们实际上可以看到人们在日常工作中将代码提交给C#编译器.NET Core等项目。ASP.NET Core

Even more interestingly, we can look at David's github here https://github.com/davidfowl and then under Repositories see what he's up to, filter by language and type, and explore! Sometimes I just explore the Pull Requests on projects like ASP.NET Core.

更有趣的是,我们可以在这里查看David的github https://github.com/davidfowl ,然后在“存储库”下查看他的工作,按语言和类型进行过滤并进行探索! 有时,我只是在ASP.NET Core之类的项目上探讨Pull Requests

You can have Private repositories on GitHub, as I do, and as I'm sure David does. But GitHub is a social network for code and it's more fun and a better learning experience when we can see each others code and read it. Read with a critical eye, but without judgment as you may not have all the context that the author does. If you went to my GitHub, https://github.com/shanselman you might be disappointed but you also may be missing the big picture. Just consider that as you Follow people and explore their code.

您可以像我一样并且可以确定David可以在GitHub上拥有私有存储库。 但是GitHub是一个用于代码的社交网络,当我们可以看到彼此的代码并阅读它们时,它会更有趣,并且学习体验更好。 用批判的眼光看书,但不要作判断,因为您可能没有作者所拥有的全部上下文。 如果您访问我的GitHub, https://github.com/shanselman,您可能会感到失望,但您可能也错过了总体情况。 在关注他人并探索他们的代码时,请考虑一下。

David is an advanced .NET developer, while, for example, I am comparatively intermediate. So I realize that not all of David's code is FOR me. It's a scratchpad, it's not educational how-to workshops. However, I can get pick up cool idioms, interesting directions the tech may be going, and more importantly - prototypes and spikes. Spikes are folks testing out technical ideas. They may not be complete. In fact, they may never be complete. But some my be harbingers of things to come.

David是高级.NET开发人员,而例如,我是中级。 因此,我意识到并非David的所有代码都适合我。 这是一个便签本,不是教育性的操作讲习班。 但是,我可以学到一些很酷的习语,该技术可能会发展出的有趣方向,更重要的是,可以找到原型和峰值。 尖刺是测试技术思想的人们。 它们可能不完整。 实际上,它们可能永远都不完整。 但是我有些预示即将发生的事情。

Here's a few things I learned today.

这是我今天学到的一些东西。

.NET Core的gRPC (gRPC for .NET Core)

For example, at https://github.com/davidfowl/grpc-dotnet I can see David has forked (copied) gRPC for dotnet and his game is working with the gRPC folks to make a fully supported version of gRPC for production workloads with .NET Core! Here are the stated goals:

例如,在https://github.com/davidfowl/grpc-dotnet上,我可以看到David分叉了(复制的)gRPC for dotnet,他的游戏正在与gRPC人员合作,为具有生产负载的gRPC制作一个完全受支持的gRPC版本。 .NET核心! 既定目标如下:

  • We plan to implement a fully-managed version of gRPC for .NET that will be built on top of ASP.NET Core HTTP/2 server.

    我们计划为.NET实施完全托管的gRPC版本,该版本将建立在ASP.NET Core HTTP / 2服务器之上。
  • Good integration with the rest of ASP.NET Core ecosystem

    与其他ASP.NET Core生态系统的良好集成
  • High-performance (we plan to utilize some of the cutting edge performance features from ASP.NET Core and in .NET plaform itself)

    高性能(我们计划利用ASP.NET Core和.NET平台本身的一些最先进的性能功能)

That sounds cool! I can go learn that gRPC is a modern (google sponsored) Remote Procedure Call framework that can run anywhere. It's used by Netflix and Square and supports basically any languaige and any environment. Nice for this microservice world we are entering and hopefully has learned from the sins of DCOM and CORBA and RMI, because I was there and it sucked.

听起来不错! 我可以了解到gRPC是可以在任何地方运行的现代(由Google赞助)的远程过程调用框架。 它由Netflix和Square使用,基本上支持任何语言和任何环境。 对于我们正在进入的这个微服务世界来说,这是一件好事,希望我从DCOM和CORBA和RMI的罪恶中吸取了教训,因为我在那里并且很烂。

在这里什么也看不到,而是转移到新的JSON序列化器 (Nothing to see here but moving to a new JSON serializer)

This Web.Framework sounds fun, and I'll be sure to take the description to heart.

这个Web.Framework听起来很有趣,我一定会牢记其描述。

says "Lame name, just a prototype, nothing to see here (move along)"

You can see David and James Newton-King kicking ideas around as you explore the commit log. However, the most interesting commit IMHO is when David moves this little spike from using JSON.NET (the ubiquitous 3rd party JSON serializer) to the new emerging official System.Text.Json. Here is the commit with unified differences.

探究提交日志时,您可以看到David和James Newton-King提出想法。 但是,最有趣的提交恕我直言是David将这个小小的尖峰从使用JSON.NET(无处不在的第三方JSON序列化程序)转移到新出现的官方System.Text.Json上。 这是具有统一差异的提交

It's a small change but it also makes me feel good about the API underneath this new JSON API that's coming. My takeway is that it's not as scary as I'd assumed. Looks like a Good Thing(tm).

这是一个很小的变化,但也使我对即将推出的新JSON API下的API感到满意。 我的看法是,它没有我想象的那么可怕。 看起来不错。

A diff of code shows that just one line is changed to move JSON serializers

Cool!

凉!

多协议ASP.NET Core (Multi-Protocol ASP.NET Core)

This looks interesting.

这看起来很有趣。

"The following sample shows how you can host a TCP server and HTTP server in the same ASP.NET Core application. Under the covers, it's the same server (Kestrel) running different protocols on different ports. The ConnectionHandler is a new primitive introduced in ASP.NET Core 2.1 to support non-HTTP protocols."

“下面的示例演示了如何您可以承载一个TCP服务器和HTTP在同一个ASP.NET核心应用服务器。在幕后,这是在同一台服务器(红隼)在不同的端口上运行不同的协议。该ConnectionHandler是一个新的基元介绍支持非HTTP协议的ASP.NET Core 2.1。”

I didn't know you could do that! Looks like this sample hasn't changed much since it was conceived of in 2018, but then in the last month it's been updated twice and it appears to be part of a larger, slow-moving architectural issue called Bedrock that's moving forward.

我不知道你能做到! 自2018年构思以来,该示例似乎并没有太大变化,但是在最后一个月中,它进行了两次更新,并且似乎是一个越来越大的,进展缓慢的,名为Bedrock建筑问题的一部分。

I learned that Kestral (the ASP.NET Core web server) has a "ListenLocalhost" option on its options object!

我了解到Kestral(ASP.NET Core Web服务器)在其options对象上具有“ ListenLocalhost”选项

WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
// This shows how a custom framework could plug in an experience without using Kestrel APIs directly
services.AddFramework(new IPEndPoint(IPAddress.Loopback, 8009));
})
.UseKestrel(options =>
{
// TCP 8007
options.ListenLocalhost(8007, builder =>
{
builder.UseConnectionHandler<MyEchoConnectionHandler>();
});

// HTTP 5000
options.ListenLocalhost(5000);

// HTTPS 5001
options.ListenLocalhost(5001, builder =>
{
builder.UseHttps();
});
})
.UseStartup<Startup>();

I can see here that TCP port 8007 is customer and uses a custom ConnectionHandler which I also didn't know existed! I can then look at the implementation of that handler and it's cool how clean the API is. You can get the result cleanly off the Transport buffer. You're doing low-level TCP but it doesn't feel low level.

我在这里看到TCP端口8007是客户,并且使用了一个我也不知道存在的自定义ConnectionHandler ! 然后,我可以看一下该处理程序的实现,这是多么干净的API。 您可以从传输缓冲区中完全获得结果。 您正在执行低级TCP,但不会感到低级。

using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.Extensions.Logging;

namespace KestrelTcpDemo
{
public class MyEchoConnectionHandler : ConnectionHandler
{
private readonly ILogger<MyEchoConnectionHandler> _logger;

public MyEchoConnectionHandler(ILogger<MyEchoConnectionHandler> logger)
{
_logger = logger;
}

public override async Task OnConnectedAsync(ConnectionContext connection)
{
_logger.LogInformation(connection.ConnectionId + " connected");

while (true)
{
var result = await connection.Transport.Input.ReadAsync();
var buffer = result.Buffer;

foreach (var segment in buffer)
{
await connection.Transport.Output.WriteAsync(segment);
}

if (result.IsCompleted)
{
break;
}

connection.Transport.Input.AdvanceTo(buffer.End);
}

_logger.LogInformation(connection.ConnectionId + " disconnected");
}
}
}

Pretty slick. This just echos what is sent to that port but not only has it educated me about a thing I didn't know about, it's something I can mentally file away until I need it!

很漂亮这只是回显发送到该端口的内容,但不仅使我了解到我不知道的事情,而且我可以在不知不觉中将其归档!

All of these things I learned in just 30 minutes of exploring someone's public repository.

在探索某人的公共存储库的短短30分钟内,我学到了所有这些东西。

What kinds of code do you like to read and what have you learned from just poking around?

您喜欢阅读哪些类型的代码,并且从中学习也学到了什么?

Sponsor: Get the latest JetBrains Rider for remote debugging via SSH, SQL injections, a new Search Everywhere popup, and improved Unity support.

赞助商:获取最新的JetBrains Rider,以通过SSH,SQL注入,新的“搜索无处不在”弹出窗口以及改进的Unity支持进行远程调试。

翻译自: https://www.hanselman.com/blog/learning-about-net-core-futures-by-poking-around-at-david-fowlers-github

martin fowler

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值