PRISM = 6.3; Unity interception=5.3;
I am refactoring a class to remove crosscutting concerns using Unity Interception with PRISM viewModelLocator = true.
In Module I register the interface and class along with identifying an interceptor:
Container.RegisterType<ITaxViewModel, TaxViewModel>(
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<LoggingInterceptionBehavior>());
I run the application then press the tax button and I get the following error:
System.Windows.Markup.XamlParseException HResult=0x80131501
Message='Set property 'Prism.Mvvm.ViewModelLocator.AutoWireViewModel' threw an exception.' Line number '8' and line position '14'.
Source=PresentationFrameworkStackTrace: at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at FOO.Views.TaxView.InitializeComponent()
in C:\FooControlLibrary\Views\TaxView.xaml:line 1
Inner Exception 1: ActivationException: Activation error occurred while trying to get instance of type TaxViewModel, key ""
Inner Exception 2: ResolutionFailedException: Resolution of the dependency failed, type = "FOO.VM.TaxViewModel", name = "(none)". Exception occurred while: while resolving. Exception is: ArgumentException - The type FOO.VM.TaxViewModel is not interceptable. Parameter name: interceptedType
At the time of the exception, the container was:
Resolving FOO.VM.TaxViewModel,(none)
Inner Exception 3: ArgumentException: The type FOO.VM.TaxViewModel is not interceptable. Parameter name: interceptedType
I'm not sure if PRISM can resolve the proxy created by Unity. Does anyone know how to do this?
I can without Exception. Prism.Unity : 6.3.0 Unity.Interception : 4.0.1
protected override DependencyObject CreateShell()
{
Container.AddNewExtension<Interception>();
Container.RegisterType<jobsRepository>(new Interceptor<VirtualMethodInterceptor>(),
new InterceptionBehavior<LogBehavior>());
var jobsRepo = Container.Resolve<jobsRepository>();
jobsRepo.GetJobs();
return Container.Resolve<MainWindow>();
}
IInterceptionBehavior
public class LogBehavior : IInterceptionBehavior
{
public bool WillExecute => true;
public IEnumerable<Type> GetRequiredInterfaces()
{
return Enumerable.Empty<Type>();
}
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
Debug.WriteLine("# before: " + input.MethodBase.Name);
var result = getNext()(input, getNext);
Console.WriteLine($"# end:{input.MethodBase.Name}");
return result;
}
}
User contributions licensed under CC BY-SA 3.0