Skip to content

Keyed Services Support in MvvmToolkit.Mvvm #803

@Touseefelahi

Description

@Touseefelahi

Discussed in #800

Originally posted by Touseefelahi November 23, 2023
How to use keyed services in my Avalonia Application?
I am trying to use the keyed services feature from .net 8, but it is not working for me.

This is what I have in my App.axaml.cs file

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using CommunityToolkit.Mvvm.DependencyInjection;

var services = new ServiceCollection();
services.AddKeyedTransient<IUnitOfWork, UnitOfWork>(ServiceList.LocalDB);
Ioc.Default.ConfigureServices(ConfigureServices());

This is how I am trying to get the keyed service in some other class

Ioc.Default.GetRequiredKeyedService<IUnitOfWork>("LocalDB");

This is the error that I am getting:

This service provider doesn't support keyed services.

Am I missing something here? or the feature is not implemented yet?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions