New Posts New Posts RSS Feed: [Import] from a console application
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

[Import] from a console application

 Post Reply Post Reply
Author
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Topic: [Import] from a console application
    Posted: 09-Mar-2012 at 12:17pm
Hello,
I've got a WPF application that works with an assembly to show reports (telerik reporting is the third part component)
Inside my wpf application I use the [Import] to injiect the application repository and it's ok...

I've been asked to create a console application that will generate report in a batch, was wondering how can I do the Import/Export of composition model considering I've got no bootstrapper... Can I define in the program.cs an export of the IApplicationRepository and IUserService?

Thanks
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 11-Mar-2012 at 12:53am
MEF is available even in a console app and DevForce out of the box, makes sure that there's a container and catalog, so yes, you can do imports and exports.
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 15-Mar-2012 at 2:46am
Hello Marcel,
I'm getting a bit lost... I have to add manually my repositories to the catalog, the MEF discovery isn't done in automatica way... and I don't have to create a framework boostrapper, am I rigth?
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 16-Mar-2012 at 1:09am
You can't use Cocktail in your console app if that's what you are trying to do. Cocktail brings dependencies to WPF with it. It might work, I've never tried it, but one really shouldn't. As it stands today, Cocktail only supports WPF and Silverlight clients. It doesn't support console apps and it doesn't support server-side apps. It is a framework to build GUI clients in WPF or Silverlight.
 
What I meant is that MEF is still available in console apps. DevForce does its part and creates the catalog and container which are available through CompositionHost.Instance.
 
So, if you have classes decorated with the [Export] attribute, they will automatically end up in the MEF catalog and then you can pull instances from the container, by using the helper methods on CompositionHost and/or use the MEF API directly to interact with CompositionHost.Instance.Container.
 
 
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 16-Mar-2012 at 8:44am
Hello Marcel,
I've got a problem getting my IApplicationRepository... I check and it's as a part in the Container.Catalog...
 
I got this log uploads/1136/a1.txt
 
I don't really know what to put in my program.cs to compose the container... I've seen that I've 7 exports but I can only access to one (IEntityManagerProvider<MyEntities>) ... please tell me how to configure it..
 
I'm almost sure the problem is related to
 
2012-03-16 16:39:28  Cocktail.Composition:WarnIfNotConfigured WARNING: Composition has not been configured. Not all types may be available.
 
 Thanks
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 16-Mar-2012 at 10:09am
Unfortunatley, if you insist on moving forward with using Cocktail in a console app against my advise, I can't support you. I did not develop Cocktail to be used in a console app. I have no idea what might work and what not and what issues you might run into like this one.
As I said before, DevForce already builds the catalog and composes the container. There's nothing to do. The warning you are getting is simply telling you that Cocktail didn't compose any of it's stuff into the container. You would configure it with Composition.Configure. Maybe that will do the trick if your ApplicationRepository depends on something that is not in the container, but if you are seeing IApplicationRepository, then MEF picked it up. It sounds like MEF fails trying to create an instance of the repository.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down