Когда пользователь вошел в систему, вызовите этот метод:
Код: Выделить всё
public IService Select(SelectServiceRequest request)
{
IAxxxService anagServ = IoC.Container.Resolve(request.GetRegisteredService().ToString());
return xxxServ;
}
- с реализацией GetRegisteredService() с ClientIdentifier = 0 для первого выполнения
Код: Выделить всё
public RegisteredServices GetRegisteredService() { RegisteredServices res = RegisteredServices.Estxxx; if (ClientIdentifier == 0) { res = RegisteredServices.Anaxxx; } else if (ClientIdentifier == 1) { res = RegisteredServices.Prixxx; } else if (ClientIdentifier == 2) { res = RegisteredServices.Estrxxx; } else if (ClientIdentifier == 3) { res = RegisteredServices.LixxAnagrxx; } return res; }
с реализацией кода IOC и инициализацией:
}Код: Выделить всё
internal class IoC{ private static IUnityContainer container = new UnityContainer(); private static bool isInitialized = false; public static IUnityContainer Container { get { if (!isInitialized) { lock (container) { if (!isInitialized) container.RegisterType(RegisteredServices.Esxxxxx.ToString()); container.RegisterType(RegisteredServices.Anaxxxx.ToString()); container.RegisterType(RegisteredServices.Prixxxx.ToString()); container.RegisterType(RegisteredServices.LixxxAnagxx.ToString()); isInitialized = true; } } } return container; } }
У меня есть это исключение в методе выполнения «Resolve»:
System.Reflection.TargetInvocationException: Исключение было
создано целью вызова.
---> Microsoft.Practices.Unity.ResolutionFailedException: не удалось разрешить зависимость, введите =
«ApCon.IService», name = «Anagxxx». Сообщение об исключении:
Текущая операция сборки (ключ сборки Build Key[ApCon.StandardService, Anaxxxx]) не удалась:
Текущая операция сборки (ключ сборки Build Key[ApCon.StandardService, Anaxxxx]) не удалась: индекс находился за пределами
границ массива.
(Тип стратегии DynamicMethodConstructorStrategy, индекс 0) (Тип стратегии BuildPlanStrategy, индекс 3)
---> Microsoft.Practices.ObjectBuilder2.BuildFailedException:
Текущая операция сборки (ключ сборки Build Key[ApCon.StandardService, Anagrafe]) завершилась неудачно:
Текущая операция сборки (ключ сборки Build) Key[ApCon.StandardService, Anagrafe]) не удалось: индекс находился за пределами
границ массива.
(Тип стратегии DynamicMethodConstructorStrategy, индекс 0) (Тип стратегии BuildPlanStrategy, индекс 3)
---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: текущая операция сборки
(ключ сборки Build Key[ApCon.StandardService, Anagxxx]) завершилась неудачей:
Индекс находился за пределами массива. (Тип стратегии DynamicMethodConstructorStrategy, индекс 0)
---> System.IndexOutOfRangeException: Индекс вышел за пределы массива. в
System.Collections.Generic.List1.Add(T item) в
Microsoft.Practices.ObjectBuilder2.DependencyResolverTrackerPolicy.AddResolverKey (ключ Object
) в
Microsoft.Practices.ObjectBuilder2.ConstructorSelectorPolicyBase`1.CreateSelectedConstructor(контекст IBuilderContext
, ConstructorInfo ctor) в
Microsoft.Practices.ObjectBuilder2.ConstructorSelectorPolicyBase1.SelectConstructor(контекст IBuilderContext
) в
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext
context) в
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) --- Конец внутренней трассировки стека исключений --- в
Могло бы быть инструкция по блокировке? Кажется, типы не были зарегистрированы и isInitialized стал истинным
Подробнее здесь: https://stackoverflow.com/questions/367 ... ncy-failed
Мобильная версия