.net core5 summary 课程记录 Pay for what use

1.   .net core 默认集成了 Kestrel。IIS对于.netcore 的作用是监听转化,所以一般都是ngix+Kestrel.

 

 2.  命令行启动.netcore  /bin/xxx.dll urls=http://localhost:portnumber  --port:portnumber  .    前提把发布目录下的wwwroot文件复制到编译目录下,然后指定app.UseStaticFiles(new StaticFileOptions(){ FileProvider=new PhysicalFIleProvider(Path.Combine(Directory.GetCurrentDirectory(),@"wwwroot"),});   

3.nginx  负载均衡

   

upstream Net5{
server localhost:5177 weight=1;
server localhost:5178 weight=5;
server localhost:5179 weight=10;
}

server {
listen 8080;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
proxy_pass http://Net5;
}

proxy

 

4 .  支持命令行参数。在main函数里add

    new ConfiguaratioBuilder().SetBasePath(Directory.GetCurrentDirectory())
                                               .AddCommandLine(args) //支持命令行
                                               .Build();

   使用是  用IOC  .then   this._iConfiguration["port"]

5 负载均衡下 Session 不能共享

     session共享    1 stateserver  2 sqlserver  3 redis

     Cookie 验证     --token(JWT)

 6  a)接口最小化设计。比如ISession  。 SessionExtension

     b)组件化开发 abstact     reality         extension 

     c)IOC 抽象依赖

7 ASP.net管道处理模型,环节固定,通过事件完成扩展。 所以在.net 5 中使用middleware

   

 

 

 8. redis做Session共享  Microsoft.Extensions.Caching.Redis 

         在ConfigureService     services.AddDistributedRedisCache(options=>{

    

     options.instanceName=“Net5Redis”;options.Configaration="127.0.0.1:6379"

})  

9.   利用了2层委托 realize pipeline.    试试   delegate invoke method.

10 AOP  aspect  oriented programming

 

   在MVC中的应用     创建一个FillterAction类 Inherit  Attribute,IActionFilter, 然后在control的Index里添加这个类作为Atribute

如果在Filter里直接返回JsonResult。则此断路器,断的是MVC流程。不会断其他的filter。 

   创建一个FillterResource类 Inherit  Attribute,IRecouceFilter, 然后在control的Index里添加这个类作为Atribute

还有  FilterAction

 

11 AutoFac   nuget  Autofac.Extensions.DependencyInjection   and Autofac.Extras.DynamicProxy

  CreateHostBuilder里  .UseServiceProviderFactory

 

12 缓存

 

 

 

 

 

 

 

---------------   关于服务注册    

AddTransient瞬时模式:每次请求,都获取一个新的实例。即使同一个请求获取多次也会是不同的实例

        HttpContext.RequestServices.GetService<IUserBLL>.GetSomeDynamicProportyLikeGetDateTime   .  同一个请求,多个调用,会有不同的值

AddScoped:每次请求,都获取一个新的实例。同一个请求获取多次会得到相同的实例

AddSingleton单例模式:每次都获取同一个实例

--------------  About  extension 

        you can extension some interface or class 。 Use static  methodName(this (name that you want to extension class or interface ). then you can use this class or interface method . 

        if the class you derived already have same name properity. the method you extend not effect.

posted on 2021-03-15 15:03  developer1980  阅读(91)  评论(0)    收藏  举报

导航