Replace .NET核心-更改控制器中的依赖项
我正在处理一个web应用程序(.net core 2.2),并尝试替换控制器中querystring参数的现有依赖项。我知道,可以在Startup.cs(ConfigureServices(IServiceCollection services)方法)中替换依赖项。但问题是我无法访问控制器中的“IServiceCollection”。你们有办法做到吗 这是在启动时替换依赖项的方法。“ServiceCollectionDescriptor”具有“替换”方法Replace .NET核心-更改控制器中的依赖项,replace,dependency-injection,Replace,Dependency Injection,我正在处理一个web应用程序(.net core 2.2),并尝试替换控制器中querystring参数的现有依赖项。我知道,可以在Startup.cs(ConfigureServices(IServiceCollection services)方法)中替换依赖项。但问题是我无法访问控制器中的“IServiceCollection”。你们有办法做到吗 这是在启动时替换依赖项的方法。“ServiceCollectionDescriptor”具有“替换”方法 services.Replace(ser
services.Replace(servicescriptor.Scoped())代码>
谢谢诸如此类的东西……
公共类服务集合
{
在控制器中--
public class YourController : Controller
{
public YourController (ServicesCollections obj)
{
Configuration = obj.Configuration;
Services = obj.Services;
ConfigureServices();
}
public IConfiguration Configuration { get; }
public IServiceCollection Services { get; }
public void ConfigureServices()
{
}
这无法存储服务集合!控制器中的obj始终为空!
services.Configure<CookiePolicyOptions>(options =>
{
//This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.None;
}
);
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Latest);
services.AddMvc()
.AddControllersAsServices();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddRazorPages();
var configs = Interfaces.SingleObject<Interfaces.ServicesCollections>.Instance(Configuration, services);
services.AddScoped<ServicesCollections>();
services.AddTransient(ctx => new SSO.Gateway.Web.Controllers.LoginController(configs));
}
public class YourController : Controller
{
public YourController (ServicesCollections obj)
{
Configuration = obj.Configuration;
Services = obj.Services;
ConfigureServices();
}
public IConfiguration Configuration { get; }
public IServiceCollection Services { get; }
public void ConfigureServices()
{
}