Prism Unity interception error

0

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=PresentationFramework

StackTrace: 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?

c#
wpf
unity-container
prism
asked on Stack Overflow Jan 8, 2018 by kcabral • edited Jun 20, 2020 by Community

1 Answer

0

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;
    }
}
answered on Stack Overflow Aug 4, 2018 by S.Hashiba • edited Aug 18, 2018 by Hossein Golshani

User contributions licensed under CC BY-SA 3.0