.NETCORE 依赖注入服务生命周期
依赖注入服务有3种生命周期:Transient;Scoped;Singleton Transient:即用即建,用后即弃。就是每次获取这个服务的实例时都要创建一个这个服务的实例。 Scoped:这种类型的服务实例保存在当前依赖注入容器(IServiceProvider)上,这个后面会有详细的讲解。 Singleton:单例。即只保存一个服务实例 下面我们来做一个实例的演示,让大家可以更深入地理解这3中生命周期 我的测试环境:win10+vs2019+.net core 3.1 新建一个.NET CORE的控制台应用,添加NuGet包:Microsoft.Extensions.DependencyInjection和Microsoft...
.netcore docker 使用 UseUrls 绑定端口时无法访问
.netcore docker 使用 UseUrls 绑定端口时无法访问 目录结构 Dockerfile FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 8080 COPY ./publish . ENV TZ=Asia/Shanghai ENTRYPOINT ["dotnet","CAS.Api.dll"] 生成容器: docker build -t cas.api . 能够正常启动: docker run -d -p 8080:8080 cas.api docker ps -a 浏览器缺无法访问!!! 服务器是没有打开防火墙的,应该不是这个问题。 进容器内去看看能不能访问: docker exec ...
Ocelot+Consul+.netcore高可用&动态伸缩
Ocelot 网关: publicclassStartup { publicStartup(IConfiguration configuration) { Configuration= configuration; } publicIConfigurationConfiguration{ get;} // This method gets called by the runtime. Use this method to add services to the container. publicvoidConfigureServices(IServiceCollection services) { var config =newConfigurationBuilder() .AddJsonFile("Ocelot.json",false,true) .Build(); services.AddOcelot(config).AddConsul(); servic...
.netcore获取客户端电脑名和IP
public string GetUserName() { var username = System.Net.Dns.GetHostEntry(Request.HttpContext.Connection.RemoteIpAddress).HostName; return username; }
在IIS7上部署你的ASP.NET Core 2项目
在IIS上部署你的ASP.NET Core 2.1项目 注:你的web,必须通过publish到目录,iis再指向目录才行。不能直接用IIS指向VS开发目录。(以前.NET STANDARD一直这样,结果.NETCORE不行。) 1、在控制面板→程序→启用或关闭Windows功能→勾选Internet Information Services以及Web管理工具下的IIS管理控制台 2、IIS 安装AspNetCoreModule 模块 https://www.microsoft.com/net/download/windows 安装完后一定要重启,否则 Http Error 502.5 3、发布 项目右键--发布 4、添加网站 添加一个网站,设置一下名称,并将路径...