Hello. There are several examples of using MEF to plugin whole controller/view packages into a MVC application, but i didn't found one, using MEF to plugin funcional parts, used by other controllers.
For example, think of a NewsService with a simple interface like
interface INewsService
{
List<NewsItem> GetAllNews();
}
That gets news wherever he wants, and returns them in a List of NewsItems. My page should load an exported INewsService and show the news on the page.
But there is the problem. I cant just use [Import] in the controllers, as they are just created when they are needed.
Edit: (Importing them to the main MVCApplication class doesn't work, becouse i cant access it from the controllers.) I think i found a way to access the main app via HttpContext.ApplicationInstance. But the Service object in this instance is null although it was created successfully in the Application_Start() method. Any idea why?
So, how can i access the NewsService from within a controller?
Thanks in advance, Marks