Web1 day ago · After that the app successfully migrated the database, but I have an error, when I am trying to add the ApplicationDbContext to dependency injection during runtime. Below is the example full code of .Migrate() function (for sql server) as well as adding the ApplicationDbContext to dependency injection: WebC# 如何将运行时参数作为依赖项解析的一部分传递?,c#,dependency-injection,asp.net-core,.net-core,C#,Dependency Injection,Asp.net Core,.net Core,我需要能够将连接字符串传递到我的一些服务实现中。我在构造函数中执行此操作。
c# - How can I pass a runtime parameter as part of the dependency ...
WebOct 10, 2024 · public static void RegisterComponents () { var container = new UnityContainer (); container.RegisterType (); container.RegisterType (); DependencyResolver.SetResolver (new UnityDependencyResolver (container)); } c# entity-framework dependency-injection … WebThe connection is being kept for the life time of the repository. – Palle Due Nov 19, 2024 at 11:21 1 The connection will get disposed at the end of the request as IDbconnection is injected using Transient service like services.AddTransient ( (sp) => new SqlConnection (dbConnectionString)); – Sunny12 Nov 19, 2024 at 11:53 honey slush
Dependency injection - .NET Microsoft Learn
WebYou can do this with the GetConnectionString extension-method: string conString = Microsoft .Extensions .Configuration .ConfigurationExtensions .GetConnectionString (this.Configuration, "DefaultConnection"); System.Console.WriteLine (conString); or with a structured-class for DI: Web2 days ago · Don't use private ApplicationDbContext db = new ApplicationDbContext(); Instead add a constructor to your DAL class with ApplicationDbContext as a parameter. It will automatically resolve the ApplicationDbContext from the Dependency Injection container as it is already configured in startup.cs in Configuration class with the … WebApr 14, 2024 · As simple as I can put it, I have the following: public async Task Run ( [QueueTrigger ("order-new", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log) Is there any way I can do something like: public async Task Run ( [QueueTrigger ("order-new", Connection = _connection)]string myQueueItem, ILogger log) honey smacks cereal dupe