All Questions
Tagged with asp.net-core-3.0 dependency-injection
18
questions
0
votes
0
answers
32
views
How to Resolve IWebHostEnvironment in .NET Core 8.0? [duplicate]
I'm working on migrating a project from ASP.NET Core 5.0 to .NET Core 8.0. In my project,
using Test_Site_1.Application.Interfaces.Contexts;
using Test_Site_1.Common.Dto;
using Test_Site_1.Domain....
0
votes
1
answer
720
views
Problem Registering services for DI in NET CORE 3
I am applying dependency injection to my dotnet 3.1 project. I created a class ServiceRegister in my Application layer:
namespace Microsoft.Extensions.DependencyInjection
{
public static class ...
0
votes
1
answer
774
views
.NET Core 3 dependency injection in custom validation [duplicate]
I want to make a custom validation attribute in .NET Core called CheckIfEmailExists. I want to make sure the user is not in my database already. So this is my create user view model:
public class ...
5
votes
1
answer
7k
views
How to inject an IServiceScope into a class in .NET Core
I have a problem with injecting Microsoft.Extensions.DependencyInjection.IServiceScope into my class.
My service implementation:
public class AccountService : IAccountService
{
private readonly ...
14
votes
2
answers
2k
views
Is there a robust way to register dependencies in ASP.NET Core 3.1 beside adding everything into Startup class?
I have an ASP.NET Core 3.1 project. Typically, I register any dependency using the ConfigureServices() method in the Startup.cs class.
But, I find myself having to register lots of dependencies and ...
7
votes
0
answers
7k
views
ASP.NET Core 3.0 - Cannot access a disposed object. Object name: 'IServiceProvider'
We have windows service that hosts web api and does some calculation job in background.
From time to time we get exception:
2019-12-27 11:49:15.525 +01:00 [Error] [Serilog.Log.Write] Unhandled ...
4
votes
1
answer
2k
views
ASP.NET Core 3 - immediately instantiate a singleton after services.AddSingelton<IMySingletone, MySingletone>();
How to immediately instantiate a singleton after
services.AddSingelton<IMySingleton, MySingleton>()
I'm using this dirty workaround for now (call GetService in every request):
public void ...
1
vote
1
answer
3k
views
What is the best practice to configure httpClients in ASP Net Core 3.0 during startup?
ASP NET Core 2.1 gave us HttpClientFactory which is a great way to build custom httpClients.
We used this method together with an endpoint configuration service that was injected into the constructor ...
2
votes
1
answer
799
views
Is there any way to initialize settings model of c# on startup from the JSON settings available in the database in .net core?
I have created a web application in which I am using .net core 3.0 as server-side technology and have Postgres as backend. I have a table called settings in the database in which I am storing settings ...
4
votes
4
answers
6k
views
How do I auto-register/resolve services by their interface?
I'm developing a MVC .NET Core 3/Angular/Entity Framework application. My application will likely have a lot of repositories in it. To support this I would like to resolve the service (repository) by ...
0
votes
1
answer
285
views
DI Registration service type .net core 3.0
I have one n-tier layered app and in Infrastructure module where I'm trying to develop sending email for confirmation an user, I'm getting an error.
No service for type
'IMS.Infrastructure....
1
vote
1
answer
1k
views
AddSingleton - Create on run application
I need to create singletons when the application starts. In this example, I create an instance of IdentityOptions with new values. The problem is that when I start the application and I want to create ...
10
votes
2
answers
14k
views
Pass a child component as Parameter in Blazor
I would like to do in Blazor something that I normally do in React: create a reusable component that internally uses other child components, with the ability to pass those child components as ...
1
vote
1
answer
4k
views
How can I inject a service into a static method in .net core
I'm writing an html helper that will do some calculations for me. Now because it is a helper it is a static method. For example:
public class MyHelper
{
public static HtmlString DoSomething()
...
3
votes
0
answers
475
views
MediatR send generic type class
I've been trying to send generic type class via mediator.
I created a CreateSettingCommand class that accepts any model via:
var createUserCommand = new CreateSettingCommand<Database.Models....