❔ .net core 6 IConfiguration Injection
Hi there - i'm going nuts try to solve this simple problem. I have a .net Core 6 WebApplication builder based app, and all i'm trying to do is get to IConfiguration in my service classes.
From what i've read, .net 6 should automatically add its IConfiguration service to the build services, and therefore my AddService<MyClass> constructor whcih has public MyClass(IConfiguration configuration) in it throws "The service implementation object was not initialized or is not available." and it's not hitting breakpoints. Remove IConfiguration from teh constructor, it works
it's like either a) IConfiguration is not injected into the services for the app builder, or b) MyClass is not subject to being DI'd by asp.net.
argh
18 Replies
if I inspect app just before calling Run() "{[{Name = IConfiguration FullName = Microsoft.Extensions.Configuration.IConfiguration}, {Method = {System.Object <CreateServiceAccessor>b__1(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope)}}]}" this is in the realizedServics list
Did you somehow use a different namespace for IConfig param in MyClass?
well i dont think so
let me double check
Microsoft.Extensions.Configuration.IConfiguration
thats what VS thinks it is hovering over the parameter to the service class constructor
That's weird. Do you have a Startup class?
no, just Program.cs
magic net6 stuff that freaks me out 🙂
its this IntefleCSService that can't be created
public IntefleCSService(IConfiguration configuration)
{ _config = configuration; }
Idk, thought it should be free. Maybe something peculiar with WCF core
Not that this solves your problem, but in many circles it's considered bad practice to scatter iconfiguration across your app.
fair, instead pass options into the service contstructor? Or reference the orgiinal app class?
Options is good
That doesn't solve your problem
What packages do you have
CoreWCF.Http, CoreWCF.Primites and System.Data.SqlClietn
Microsoft.AspNETCore.App and Microsoft.NetCore.App
Have you tried createdefaultbuilder?
I don't recall all the differences
I don't do much with aspnet, they both handle config iirc but I could wrong
starst with this var builder = WebApplication.CreateBuilder(args);
Ugh I'll need to look not on my phone 😦
Do you have a repo?
lol dont worry, I've gotta head out shortly, nah its privvy
Kk
thanks for looking tho
I'll look on a bit
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.