Stephen Dougherty
Stephen Dougherty

Reputation: 31

MEF method Equivalent in Prism Unity

Hoping that someone might point me in the right direction. I have been refactoring a WPF application that I wrote (fairly Complex - to me), to evaluate Prism and Unity over MEF.

I have run into an issue with the ServiceFactory pattern using Unity - that I do not know how to overcome. Being a beginner with all these technologies is certainly not helping any.

Is there an Equivalent way with Unity to get the Same result as the Below Code?

[Export(typeof(IServiceFactory))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class ServiceFactory : IServiceFactory
{
    T IServiceFactory.CreateClient<T>()
    {
        return ObjectBase.Container.GetExportedValue<T>();
    }
}

Kind Regards and thanks in advance. Stephen

Upvotes: 0

Views: 221

Answers (1)

mm8
mm8

Reputation: 169190

Try this (assuming that the ObjectBase.Container property returns an IUnityContainer):

using Microsoft.Practices.Unity;
...
public class ServiceFactory : IServiceFactory
{
    T IServiceFactory.CreateClient<T>()
    {
        return ObjectBase.Container.Resolve<T>();
    }
}

Upvotes: 1

Related Questions