Linked Questions

0 votes
1 answer
3k views

I want to grab a value from the database in my Startup.cs file through a repository. However the service is not able to be resolved. I understand that I need to create an instance of my repository ...
comp32's user avatar
  • 241
173 votes
10 answers
153k views

I have a ASP.NET Core 6 MVC application, and I need to call the Database.EnsureCreated and Database.Migrate methods. But where should I call them?
bailando bailando's user avatar
166 votes
7 answers
108k views

Is it possible to resolve an instance of IOptions<AppSettings> from the ConfigureServices method in Startup? The documentation explicitly says: Don't use IOptions<TOptions> or ...
Muhammad Rehan Saeed's user avatar
133 votes
7 answers
254k views

IServiceProvider is an interface with single method: object GetService(Type serviceType); It's used to create instances of types registered in .NET Core native DI container. An instance of ...
Arkadiusz Kałkus's user avatar
125 votes
7 answers
98k views

At this point I'm injecting things into my Controllers with ease, in some cases building my own ResolverServices class. Life is good. What I cannot figure out how to do is get the framework to ...
Robert Paulsen's user avatar
59 votes
5 answers
68k views

Normally in a .NET Core project I would create a 'boostrap' class to configure my service along with the DI registration commands. This is usually an extension method of IServiceCollection where I can ...
Jason Shave's user avatar
  • 2,703
28 votes
3 answers
32k views

I am trying to implement Dependency Injection in Xunit test for AppService. Ideal goal is to run the original application program Startup/configuration, and use any dependency injection that was in ...
user avatar
29 votes
4 answers
18k views

Seems crazy that something like this is causing me such a headache. But here it is: How do you use the built-in dependency injection for net core for a non-controller class? Please provide an ...
CCPony's user avatar
  • 998
25 votes
3 answers
49k views

After a lot of reading, I have found a way to implement a custom JWT bearer token validator as below. Starup.cs: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ...
Sang Suantak's user avatar
  • 5,265
26 votes
2 answers
24k views

Do you know how to manually resolve dependencies in .net core? Something like DependencyResolver.Resolve<ISomeService>() UPDATE I'm in a class that was not injected, I want to resolve it from ...
SexyMF's user avatar
  • 11.3k
6 votes
2 answers
4k views

I am not sure if I am going about this correctly at all. Background: I have a controller action GET foo() as an example. This foo() needs to go and call bar(), and bar() may take a verrrrrry long ...
Pea Kay See Es's user avatar
13 votes
1 answer
26k views

I need to inject out of constructor, everything I declared in Setup. Ho can I do it ? How can I inject services out of constructor ? Something like Injector service in Angular 2. INJECT SERVICES ...
Tornike Choladze's user avatar
7 votes
2 answers
5k views

I have a .Net Core project that registers a number of Singletons as follows: public void ConfigureServices(IServiceCollection services) { services.AddMemoryCache(); services.AddLogging(); ...
pcdev's user avatar
  • 3,092
0 votes
2 answers
4k views

In Startup: services.AddTransient<IMyService, MyService>() Controller method: [HttpGet] public JsonResult GetSomething() { Helper helper = new Helper(new MyService()); // works but looking ...
Xeddon's user avatar
  • 449
2 votes
1 answer
2k views

I have a Class library that does a lot of File IO. Its a bit difficult to test so I wanted to start using the System.IO.Abstractions package. It has an interface that you can implement with either the ...
ourly6's user avatar
  • 23

15 30 50 per page