dependency injection - Resources and Examples of using MEF for DI/IoC -


I am highly searching and find specimens about using MEF for DI. I do not know of this, but I What I hear (actually listen in podcasts) can be used in this way ... but I am not getting any blog posts or samples.

I am using MEF in this project already (to support plugins) and thought it would be good to avail for DI.

Maybe I am barking the wrong tree?

This example can be described by an example. For example, suppose you have a core library on which you base all your bespoke apps. Call it mycompany Generally, in every app you write, MyCompany The core has to be in the context, and then the app must be called in bootstrapping and microphone. Corps to start the proper services, etc. The correct order. It does not matter much when you think that the core itself knows better how to get it started, etc.

To use MEF for dependency injection, your core will do this:

  [import ("/ application", type (IBSpoke application)) Private IBSpace application bespokeApplication ;  

The core has an auto-startup code, and it can do the same thing when it started all of its services:

  bespokeApplication Start (); In the Bespoke application, you have to export yourself:  
  [export ("/ application", typef (IBSpokappengarization))] Public Class My Approval: IBSpokeApplication {public void Start () {/ * Start app * /}}  

can now have a direct reference to MyCompany.Core in the bespoke application, and can call service directly, or you can do so Highlight that services as export and import them into the application. For example, in the core:

  [Export ("/ logging service", type (ILoggingService))] Public class NLogLoggingService: ILoggingService {/ * ... * /}  

Then in the bespoke application:

  [import ("/ logging service", type (ILoggingService))] Private ILoggingService logging service;  

... and when you want to use it:

  logging service. Log Information ("My Message");  

As far as I can tell from the literature, this dependency is the essence of injection.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -