В настоящее время у меня есть ServiceProvider, который регистрирует определенные типы из текущей сборки в одном контейнере. Я пытаюсь внедрить отдельный диалог Prism, который зарегистрирует только DialogViewModels и Dialogviews в свой собственный контейнер. Некоторые классы, зарегистрированные в ServiceProvider, требуют диалога в качестве зависимости для создания правильного диалога. Однако, когда я передаю DialogService в эти классы, я получаю следующую ошибку. < /P>
system.invalidoperationException: «Невозможно разрешить службу для типа 'prism.dialogs.idialogservice», когда пытается активировать Anansi.viewmodels.twt176xkuviewmodel'. Следует:
класс "DialogServices" реализует интерфейс Imodule.
public class DialogServices : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
throw new NotImplementedException();
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterDialog();
}
}
< /code>
Класс Appservices создает урок класса DialogServices; что, я считаю, должен зарегистрировать типы, представленные в функции RegisterTypes.
public static class AppServices
{
public static ServiceProvider? serviceProvider { get; private set; }
public static Dictionary? TypeMap { get; private set; }
public static DialogServices? dialogServices { get; private set; }
///
/// Generates a collection of types for dependency injection.
///
public static void ConfigureServices()
{
dialogServices = new DialogServices();
ServiceCollection services = new();
Type[] CurrentAssembly = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
TypeMap = new Dictionary();
foreach (Type type in CurrentAssembly)
{
TypeMap[type.Name] = type.FullName;
if (type == typeof(AppServices) ||
type.Name == "ViewModel" ||
type.Name == "Instrument" ||
type.Name == "FlowDocumentHelper" ||
type.Name == "Amplifier" ||
type.Name == "ClientHandler" ||
type.Name == "ViewViewModelMapper")
{
continue;
}
else
{
services.AddTransient(type);
}
}
serviceProvider = services.BuildServiceProvider(); // Create the dependency injection container.
}
}
Здесь я пытаюсь ввести идиалогсервис
public class TWT176XKuViewModel : AmplifierViewModel
{
public TWT176XKuViewModel(TWT176XKu amp, IDialogService dialogService)
{
_dialogService = dialogService;
Amplifier = amp;
Title = Amplifier.name;
GetCommands();
}
protected override void GetCommands()
{
if (Amplifier != null)
{
Commands = new ObservableCollection(((TWT176XKu)Amplifier).GetCommandList());
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... gistration