Skip to main content

All Questions

0 votes
0 answers
12 views

Where can I use FromService attribute in Asp.net core? [duplicate]

Hi I want to know where and when I can use fromService attribute for inject services in asp.net core?
Ershad Raoufi's user avatar
0 votes
0 answers
40 views

Issue Registering OpenAiFactory and IOpenAiChat with Rystem.OpenAi in .NET

I am having trouble registering and using OpenAiFactory and IOpenAiChat from the Rystem.OpenAi library in my .NET project. Here is my current code: public class Program { static async Task Main(...
x19's user avatar
  • 8,663
1 vote
1 answer
141 views

How can I modify a middleware or its registration to correctly use a scoped service? [duplicate]

I'm developing a multi-tenant application in .NET and I've run into an issue where I need to access a scoped service, ITenantProvider, from within a custom middleware, TenantMiddleware. However, when ...
Shahar Shokrani's user avatar
0 votes
1 answer
40 views

Accessing SignalR Hub instance from Outside Class in .net Core

I want to access my queueHub from another Class. I have the following Codes so far but I get this error while running the code. System.AggregateException: 'Some services are not able to be ...
Crisiroid's user avatar
1 vote
0 answers
104 views

ActivatorUtilities.CreateInstance is creating non-empty generic collections .Net 8

In .NET 8, when using ActivatorUtilities.CreateInstance or ActivatorUtilities.GetServiceOrCreateInstance to initalize generic collections, some of them are initlized with elements. Example: public ...
Miguel N's user avatar
2 votes
1 answer
601 views

.net 8 DI GetServices<object> not working

In one of my services I need to get all provided services. So I tried: public ServiceConstructor(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; var allServices = ...
AKuhlmann's user avatar
1 vote
2 answers
933 views

How to implement Keyed Transient Dependency Injection in C# using IServiceProvider

I have 3 SFTP providers for my application. I am trying to use newly introduced .net 8 Keyed DI feature to register these SFTP providers: var hostname1 = "hostname"; var portNo1 = 22; var ...
perpetual_noob's user avatar
0 votes
1 answer
400 views

How get all registred dbContext in .net 8?

I would like do something like this, but contexts always null: public DbCheck(IEnumerable<DbContext> contexts) Context: public class c1( DbContextOptions<c1> options ) : DbContext( ...
gyb001's user avatar
  • 29
0 votes
0 answers
27 views

How to avoid "Cannot resolve scoped service from root provider" exception? [duplicate]

I'm developing a NuGet package to handle the authentication configuration for many ASP.NET Core applications in my company. For it to work, it needs some configuration that is only available in the ...
Tao Gómez Gil's user avatar
0 votes
2 answers
170 views

How to use dependency injection for a ASP.NET Core web application?

I have created an ASP.NET Core web app which has two classes of interest: public class DBConnect { private readonly IConfiguration _configuration; public DBConnect(IConfiguration config) ...
Yan Soo's user avatar
  • 15
0 votes
2 answers
164 views

Use DI to instantiate a service with a dynamic parameter?

I have a class with below constructor: public MyClass(SomeRequiredService srs, string someRandomInput) { } How can I register MyClass with DI but with an option to pass a different someRandomInput ...
Hamid Z's user avatar
  • 327
0 votes
1 answer
53 views

Get ApiController instance at run time with .NET 7.0

I have a Web API application with 2 ApiControllers (that must be kept separated). I use dependency injection and I need to access an instance of an ApiController from the other one. Not being a ...
Sergio B.'s user avatar
  • 960
0 votes
1 answer
223 views

Replace app config with instance in tests using Options pattern

I use the C# Options pattern, e. g. with a config type like this: public class MySettings { public bool IsEnabled { get; set; } public int NumberOfDays { get; set; } } Within my tests, I ...
mu88's user avatar
  • 5,063
1 vote
2 answers
298 views

Injecting userid in DbContext for multi-tenant application

I am building a multi-tenant application with .net identity. I want each user when they log in to view their own data. I have a user resolver service where i inject httpContextAccessor to try to ...
athagiorgos's user avatar
0 votes
1 answer
79 views

Inconsistent Service Dependency References with ASP .NET Core DI

I'm working on an ASP .NET Core app with a DI setup, and I've encountered an issue related to dependency references that are not behaving as expected. I have a series of services and interfaces that ...
Sporksto's user avatar

15 30 50 per page
1
2 3 4 5
9