TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Roman Sch
NA
7
647
MEF - can't run imported function
Dec 13 2017 9:04 AM
Hi all!
Could You please help. In main program, i do import my plug-in in this way
public
static
void
LoadContainer(Unity.IUnityContainer container,
string
path,
string
pattern)
{
var dirCat =
new
DirectoryCatalog(path, pattern);
var importDef = BuildImportDefinition();
try
{
using
(var aggregateCatalog =
new
AggregateCatalog())
{
aggregateCatalog.Catalogs.Add(dirCat);
using
(var componsitionContainer =
new
CompositionContainer(aggregateCatalog))
{
IEnumerable
exports = componsitionContainer.GetExports(importDef);
IEnumerable
modules = exports.Select(export => export.Value
as
IComponent).Where(m => m !=
null
);
//((System.ComponentModel.Composition.Primitives.ExportedDelegate)exports.Select(export => export.Value).ToArray()[0]).CreateDelegate(typeof(IComponent))
try
{
var v0 = exports.Select(export => export.Value).ToArray()[0];
var v1 = (IComponent)v0;
}
catch
(Exception ex) { ex.ToString(); }
var registerComponent =
new
RegisterComponent(container);
foreach
(IComponent module
in
modules)
{
module.SetUp(registerComponent);
}
}
}
}
where IComponent is
public
interface
IComponent
{
void
SetUp(IRegisterComponent registerComponent);
String Test();
}
and exported function is
class
DependencyResolver : IComponent
{
[System.ComponentModel.Composition.Export(
typeof
(IComponent))]
public
void
SetUp(IRegisterComponent registerComponent)
{
registerComponent.RegisterType
();
}
[System.ComponentModel.Composition.Export(
"mimi"
)]
public
string
Test()
{
return
"test)"
;
}
}
The problem is in line
IEnumerable
modules = exports.Select(export => export.Value
as
IComponent).Where(m => m !=
null
);
i got always empty list, because export.Value is type {System.ComponentModel.Composition.Primitives.ExportedDelegate} and it can't be converted to type IComponent. Could You please advise me way to execute export.Value delegate?
Thanks!
PS I use VS2017 and full example is available at
https://www.codeproject.com/Articles/997216/RESTful-Day-sharp-Resolve-dependency-of-dependenci
Reply
Answers (
1
)
GetBytes method for Text, NText, or Image not for nvarchar?
Transfer files from FTP folder to Remote Desktop Folder