Questions tagged [servicecollection]
28 questions
0
votes
0 answers
Stub/Mock services depend on configuration
I have a configuration where users could select what features they want to enable/disable (i.e service) - and depend on it, if the service marked as disabled then it won't be registered in the service collection, but, I'll get other tons of null…

sunnamed
- 96
- 1
- 10
0
votes
0 answers
Does the set method of the serviceCollection need to return the previous value?
src/vs/platform/instantiation/common/serviceCollection.ts
set(id: ServiceIdentifier, instanceOrDescriptor: T | SyncDescriptor): T | SyncDescriptor {
const result = this._entries.get(id);
this._entries.set(id,…

凯文凯文
- 1
0
votes
1 answer
Register two jsonsetting in service collection in .net core
I have two hosted services, which each service use its own rabbit mq address as you can see :
{
"RabbitMQOptions": {
"HostName": "172.23.131.1",
"VirtualHost": "/",
"Port": 5672,
"Username": "**",
"Password": "***!"
},
…

Ehsan Akbar
- 6,977
- 19
- 96
- 180
0
votes
1 answer
Is multiple calls of AddRazorPages allowed?
In Program.cs I'm calling to AddRazorPages to setup Fluent Validation and some localization stuff. Unfortunately this has a lot of repetive code and I'm wondering if it is perfectly legal to reduce it by calling AddRazorPages twice?
I have tried to…

Lindstrøm
- 396
- 2
- 16
0
votes
1 answer
.NET Core 3.1 framework provided DI - how to get the instance of already registered type?
In my .NET Core 3.1 Startup.cs, I'm trying to get the instance of an already registered type i.e. IBusinessLogic using IServiceCollection, but it is not working.
How to get the instance of already registered type in .NET Core 3.1?
public class…

191180rk
- 735
- 2
- 12
- 37
0
votes
1 answer
Correct way to clean up a "Pre" instance of ServiceCollection and ServiceProvider?
I am implementing a Custom Configuration Provider in my application.
In that provider, I have to make a REST API call. That call needs a valid OAuth 2 Token to succeed. To get that token I need a semi complicated tree of class dependencies.
For…

Vaccano
- 78,325
- 149
- 468
- 850
0
votes
2 answers
How to replace registrations (at runtime) after the ServiceCollection was built?
Is this still not supported, after 3 years?
Looking at this question: .NET Core IServiceCollection Replace not refreshing
What I am trying to achieve in XamarinForms is a runtime replacement of a registered type (a data service) based on an…

Robert
- 53
- 6
0
votes
1 answer
FallbackAsync Method stops REST calls
public static IAsyncPolicy GetSaveExceptionPolicy(
IServiceProvider serviceProvider)
{
return Policy
.HandleResult(x => x.StatusCode == HttpStatusCode.Forbidden)
…

mmek123
- 13
- 5
0
votes
1 answer
Dependency Injection with XUnit Mediatr and IServiceCollection
Currently I'm able to handle IServiceCollection to inject mocks for particular services in the following manner.
public class TestClass
{
private IMediator _mediatr;
private void SetupProvider(IUnitOfWork unitOfWork, ILogger logger)
{
…

Fernando
- 614
- 1
- 9
- 20
0
votes
0 answers
Register services from controller in runtime .net core
In my project I'm loading some dll assemblies and these assemblies contains controllers as well as services need to be injected in our DI container.
I tried to find a solutions for a days using default dotnet core DI or Autofac without any…

EraMaX
- 186
- 1
- 5
-1
votes
0 answers
.NET how to apply DI for a specific assembly only
I'm using Hexagon Architecture
I have 2 driving sides, let's call them A and B (they are two difference assemblies)
The problem is the all the Dependency Injection configuration of the driving A are also applied on the driving B, and I don't want…

vu pham
- 1
- 2
-1
votes
2 answers
DI : Resolve dynamic type whilst also passing in constructor args
I have a Document class that has a list of Objects. To create and add an Object, you pass in a numeric object type id to Document.CreateObject(). Then depending on the type id, it will create the appropriate object instance.
If the id is 0, it will…

Vastar
- 9
- 4
-1
votes
1 answer
how to register generics with a different number of type parameters using .Net C# dependency injection
I have an interface that takes 2 generic type parameters and an implementation that only takes one.
How does one setup the dependency mapping in the DI container?
Given the psuedo code:
interface IDataStore
{
TEntity…

Jay
- 3,373
- 6
- 38
- 55