mef

Intercepting dependencies in MEF

ぃ、小莉子 提交于 2019-12-02 19:39:33
问题 Is it possible to intercept dependency requests in MEF before they get handled by MEF? This would be useful for implementing decorators and advanced lifetime management. Something like... catalogue.AddInterceptor<IExpensiveService>(b => ... return from pool ...); Or even... catalogue.AddInterceptor<IExpensiveService>(b => new Decorator(b())); (where 'b' is the underlying MEF resolution func for resolving the service) 回答1: Not out of the box, but you can write your own ExportProvider or

Disadvantages of Lazy<T>?

回眸只為那壹抹淺笑 提交于 2019-12-02 17:24:35
I recently started using Lazy throughout my application, and I was wondering if there are any obvious negative aspects that I need to take into account when using Lazy<T> ? I am trying to utilize Lazy<T> as often as I deem it appropriate, primarily to help reduce the memory footprint of our loaded, but inactive plugins. I'll expand a bit on my comment, which reads: I've just started using Lazy, and find that it's often indicative of bad design; or laziness on the part of the programmer. Also, one disadvantage is that you have to be more vigilant with scoped up variables, and create proper

Getting only necessary plugins with MEF in .NET

限于喜欢 提交于 2019-12-02 17:21:12
I have IMessageSender interface. using System.ComponentModel.Composition; public interface IMessageSender { void Send(string message); } And I have two plugins that implements this interface. This is plugin.cs. using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.Reflection; using System; [Export(typeof(IMessageSender))] public class EmailSender : IMessageSender { public void Send(string message) { Console.WriteLine(message); } } and this is plugin2.cs [Export(typeof(IMessageSender))] public class EmailSender : IMessageSender { public void Send

How to discover new MEF parts while the application is running?

非 Y 不嫁゛ 提交于 2019-12-02 16:51:50
I'm using MEF to load plugins in my app. Everything works, but I want new parts to be discovered when they are dropped into my app folder. Is this possible? DirectoryCatalog has a Changed event but I'm not sure how it works. This is my code right now: public sealed class RevealerFactory { private static readonly Lazy<RevealerFactory> lazy = new Lazy<RevealerFactory>(() => new RevealerFactory()); public static RevealerFactory Instance { get { return lazy.Value; } } private FileSystemWatcher watcher; private RevealerFactory() { Initialize(); } [ImportMany(RequiredCreationPolicy = CreationPolicy

How to manage discovery and composition as 2 separate concerns?

两盒软妹~` 提交于 2019-12-02 14:54:57
问题 I have set up an assembly catalog: private CompositionContainer GetContainer() { // initialize directory info ExtensionDirectory = new DirectoryInfo(settings.ExtensionsPath); // directory catalog var dirCatalog = new DirectoryCatalog(ExtensionDirectory.FullName); return new CompositionContainer(dirCatalog); } The contents of the container will load up all the assemblies in the directory as expected. I do not want to actually compose anything yet because I have constructors that will be

MEF Plugins with Security and Profiles Efficency

时光毁灭记忆、已成空白 提交于 2019-12-02 13:28:26
问题 I have an application that has many modules/plugins. I am using MEF with a Directory plugin to import them. Each user has a list of available modules stored in a database and each user can have multiple profiles controlling which modules are visible. There is an overview area showing information from all visible modules with an [ImportMany(typeof(IModule)] attribute. What is a good way of handling this so that invisible or inaccessible modules are not created in memory. 回答1: Lazy loading them

Intercepting dependencies in MEF

扶醉桌前 提交于 2019-12-02 08:22:36
Is it possible to intercept dependency requests in MEF before they get handled by MEF? This would be useful for implementing decorators and advanced lifetime management. Something like... catalogue.AddInterceptor<IExpensiveService>(b => ... return from pool ...); Or even... catalogue.AddInterceptor<IExpensiveService>(b => new Decorator(b())); (where 'b' is the underlying MEF resolution func for resolving the service) Not out of the box, but you can write your own ExportProvider or ComposablePartCatalog implementation to do this. MefContrib appears to have implemented something like that, take

How to manage discovery and composition as 2 separate concerns?

為{幸葍}努か 提交于 2019-12-02 07:42:11
I have set up an assembly catalog: private CompositionContainer GetContainer() { // initialize directory info ExtensionDirectory = new DirectoryInfo(settings.ExtensionsPath); // directory catalog var dirCatalog = new DirectoryCatalog(ExtensionDirectory.FullName); return new CompositionContainer(dirCatalog); } The contents of the container will load up all the assemblies in the directory as expected. I do not want to actually compose anything yet because I have constructors that will be injected with dependencies. What I want to do is use the AssemblyCatalog as a repository; query for a

How do I get a MEF Directory catalog looking at the same directory for both the Servicelayer and DAL?

帅比萌擦擦* 提交于 2019-12-02 06:50:32
问题 I'm using MEF to add plugins to our DAL which is used by our WebApp. This works fine, but when our service layer references the DAL, it's looking for plugins in \ServiceLayer\Plugins\ rather than \WebSite\Plugins\ (which makes sense are we're using a relative path. {DirectoryCatalog (Path="plugins/")}. The problem is if we use an absolute path it refuses to load the plugins from both the SL and the DAL, which I believe is because the path isn't within the same directory or subdiectory of the

How do I get a MEF Directory catalog looking at the same directory for both the Servicelayer and DAL?

别来无恙 提交于 2019-12-02 04:37:35
I'm using MEF to add plugins to our DAL which is used by our WebApp. This works fine, but when our service layer references the DAL, it's looking for plugins in \ServiceLayer\Plugins\ rather than \WebSite\Plugins\ (which makes sense are we're using a relative path. {DirectoryCatalog (Path="plugins/")}. The problem is if we use an absolute path it refuses to load the plugins from both the SL and the DAL, which I believe is because the path isn't within the same directory or subdiectory of the App loading the plugins(?). How can I get them to both load plugins from one folder? Thanks You can't