C
C#5w ago
SpReeD

✅ Blazor / ASP.NET - @inject keyed service

Is there a way in .NET 8 to inject a keyed service like a normal service with the @inject keyword? I know of the FromKeyedServices attribute, but cannot figure out how to use it in combination with @inject. I thought of a way like @inject [FromKeyedServices("MyService")] ServiceClass FooBar;
4 Replies
SleepWellPupper
Create a property inside a code section or a code-behind file like so:
[Inject]
[FromKeyedServices("MyService"]
public ServiceClass FooBar { get; set; }
[Inject]
[FromKeyedServices("MyService"]
public ServiceClass FooBar { get; set; }
the @inject directive is shorthand for that property without the FromKeyedServicesAttribute
SpReeD
SpReeD5w ago
Idd, so I guess it's not yet implemented, maybe in .NET 9?
SleepWellPupper
It is implemented Just not as a razor directive, likely because it is not used often enough to warrant an actual razor-"keyword".
Want results from more Discord servers?
Add your server
More Posts
Im coding my 3D engine called STRATIS and there are two errors.Im coding my 3D engine called STRATIS and there are two errors. foreach (var tri in meshCube.tris) What's the difference between webhook and sending an HTTP request to an endpoint exposed by clientHi I'm learning about building web api at the moment. Came across this concept called webhook and isIdentifying the Framework in a .csproj fileWhen you are trying to identify the framework from a csproj file, sometimes there are multiple versiMSBuild For c# project with c++ dllsSo i have a c# project and a c++ cmake project , the c# project is referenced by the actual program ✅ Typically how is an image stored?Im trying to set up an ASP.NET Project where i have a profile section. Users can then choose to uplMarshalDirectiveException: Cannot marshal 'return value': Invalid managed/unmanaged type combinationBasically trying to wrap a dll (wiiuse library) into my godot game with c# and whenever i call my wrNeed help to get data from MongoDBi have my mongodb data that like this ``` bson [ { "_id": {"$oid": "665b193178262482ba1f5bcaTrying to create objects using a loop, but don't know what i'm doing wrong?so i'm trying to update my turtle race simulator using tasks, one of the changes is to be able to chCan't get Data in Controller by Ajax from View in dotnet MVC CoreI am trying to pass data from a view to my controller. I am getting the values in Ajax correctly, buQuestion about AvaloniaSo im a beginner in Avalonia and im watching a youtube tutorial series (more specifically [this tuto