Problem with MEF and console application

Mar 19, 2012 at 12:42 PM

Hello,

I've got a problem with MEF and a console application I'm writing... I've got a dll that uses IoC to access data for generating report, this class is used within a WPF project (it used cocktail and ideablade for accessing data) and everything works fine... now I've been asked to write a batch generator for some reports but I got a nullreference exception each time I use IoC.Get<>()

 

here's my Composition() in program.cs

 


            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(@"."));
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));

            var container = new CompositionContainer(catalog);


            container.ComposeParts(this);
            var a = IoC.Get<IApplicationRepository>(); //this crashes..

 

what am I doing wrong? in the container.Catalog there's the export for the IApplicationRepository..

Thanks

Coordinator
Mar 19, 2012 at 5:34 PM

Hi ,

What does IoC.Get<T> do ?This looks like something that is specific to your implementation. Could you provide some insight?

From: advapi [email removed]
Sent: Monday, March 19, 2012 4:42 AM
To: Alok Shriram
Subject: Problem with MEF and console application [MEF:349163]

From: advapi

Hello,

I've got a problem with MEF and a console application I'm writing... I've got a dll that uses IoC to access data for generating report, this class is used within a WPF project (it used cocktail and ideablade for accessing data) and everything works fine... now I've been asked to write a batch generator for some reports but I got a nullreference exception each time I use IoC.Get<>()

here's my Composition() in program.cs


var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(@"."));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));

var container = new CompositionContainer(catalog);


container.ComposeParts(this);
var a = IoC.Get<IApplicationRepository>(); //this crashes..

what am I doing wrong? in the container.Catalog there's the export for the IApplicationRepository..

Thanks

Mar 19, 2012 at 9:32 PM

I got a nullpointer exception.... is there any guide on how to provide ioc for console applications'