Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use another ioc container with mef?
    primarykey
    data
    text
    <p>i am using mef with prism. i can use mef because i like the export, import, metadata attributes and mostly aggregate cagalog usage. so i want to use mef with prism project.</p> <p>In my plan, my solution projects must be use autofac or castle windsor ioc container and i implement like that except prism project(wpf). In case, i am not prefer to use autofac or castle windsor instead of mef's default di/ioc but too many alternative usage of personal experimantals are failed.</p> <p>Is there a any stable sample project i can use? I want to change only ioc of mef with all mef functionalty.</p> <p>My classic mef bootstrapper code is bellow Imports System.ComponentModel.Composition.Hosting Imports Microsoft.Practices.Prism.MefExtensions Imports Microsoft.Practices.ServiceLocation</p> <pre><code>Public Class Bootstrapper2 Inherits MefBootstrapper Protected Overrides Sub ConfigureContainer() MyBase.ConfigureContainer() Dim ag As New AggregateCatalog() ag.Catalogs.Add(New AssemblyCatalog(GetType(Bootstrapper2).Assembly)) ag.Catalogs.Add(New DirectoryCatalog("..\..\modules\", "Prism.Sample.Modules.*.dll")) Me.AggregateCatalog.Catalogs.Add(ag) End Sub Protected Overrides Function CreateShell() As DependencyObject Dim s As Shell = ServiceLocator.Current.GetInstance(Of Shell)() Return s End Function Protected Overrides Sub InitializeShell() Application.Current.MainWindow = Shell() Application.Current.MainWindow.Show() End Sub End Class </code></pre> <p>Shell's code is bellow: Imports System.ComponentModel.Composition</p> <pre><code>&lt;Export()&gt; _ Public Class Shell Sub New() InitializeComponent() End Sub &lt;Import(AllowRecomposition:=False)&gt; _ Public Property ViewModel() As ShellViewModel Get Return CType(Me.DataContext, ShellViewModel) End Get Set(value As ShellViewModel) Me.DataContext = value End Set End Property End Class </code></pre> <p>Now, everythings working like an expected.</p> <p>modified/overrided bootstrapper's ConfigureServiceLocator() method is bellow.</p> <pre><code>Private autofacBuilder As New Autofac.ContainerBuilder Protected Overrides Sub ConfigureServiceLocator() Dim autofacContainer = autofacBuilder.Build() Dim autofacSL = New Prism.AutofacExtension.AutofacServiceLocatorAdapter(autofacContainer) ServiceLocator.SetLocatorProvider(Function() autofacSL) End Sub </code></pre> <p>then i have got an too many resolving exception for example: exception message: Activation error occured while trying to get instance of type RegionAdapterMappings, key "".</p> <p>Prism or another code base trying to resolve IRegionAdapterMappings from the servicelocator but currentservice locator not knowns what is this.Because mef is allready registered this types((ConfigureContainer) before CreateServiceLocator.</p> <p>So, then i trying to add mef's aggregate catalog to register autofac container with Autofac.Integration.Mef project like this:</p> <pre><code>Private autofacBuilder As New Autofac.ContainerBuilder Protected Overrides Sub ConfigureServiceLocator() autofacBuilder.RegisterComposablePartCatalog(Me.AggregateCatalog) Dim autofacContainer = autofacBuilder.Build() Dim autofacSL = New Prism.AutofacExtension.AutofacServiceLocatorAdapter(autofacContainer) ServiceLocator.SetLocatorProvider(Function() autofacSL) End Sub </code></pre> <p>Then i have got a diffrent exception: IServiceLocator not registered etc...</p> <p>I have not a complately solutions for changing mef's ioc container because its own container types and uses her own extensibility. Tried to use Autofac.Integration.Mef but maybe it not future compatible. maybe not developep when mef' new releases.</p> <p>I am a big blakc hole i think. Is there a any way can't i see?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload