mef

C# Singleton Pattern and MEF

爱⌒轻易说出口 提交于 2019-12-04 02:40:51
I have a question about the Singleton Pattern and MEF. I'm new in implementing MEF Plugins and I haven't found an answer. Is it possible to provide only one instance of a class through a MEF implemented Plugin? My old class is something like this: #region Singleton /// /// This class provide a generic and thread-safe interface for Singleton classes. /// /// The specialized singleton which is derived /// from SingletonBase<T> public abstract class Base where T : Base { /* the lock object */ private static object _lock = new object(); /* the static instance */ private static T _instance = null;

C# MEF usage with static classes

亡梦爱人 提交于 2019-12-04 02:08:49
I have a static class in my solution which is used to work with various assemblies. I want to link them through MEF, so I made a field in a class. [Import(typeof(A))] static private A _a1; Then I have a method to which I pass assembly name as an argument: public static A LoadPackage(string filePath) { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(filePath)); var _container = new CompositionContainer(catalog); ??? } So is there a way now to import type from assembly specified by filepath? I can't do: _container.ComposeParts(this); since class is `static and

How to get Current ActiveDocument in Visual Studio Extension using MEF?

萝らか妹 提交于 2019-12-04 01:40:56
问题 I'm working on Visual Studio 2013 Extension using MEF while trying to read Active Document Content Type and Code. Presently it only reads at Opening Time of the Document/ProjectItem in the Editor. Once these are opened, it doesn't read these again whenever we switch between opened Document Tabs. Requirement: I want this extension to read the Content Type and Code Text of current Active Document. Updated: Problem: I know, using EnvDTE80.DTE2.ActiveWindow, I can get currently focused document,

How to use Moq to satisfy a MEF import dependency for unit testing?

瘦欲@ 提交于 2019-12-04 01:32:32
问题 This is my interface public interface IWork { string GetIdentifierForItem(Information information); } and my class public class A : IWork { [ImportMany] public IEnumerable<Lazy<IWindowType, IWindowTypeInfo>> WindowTypes { get; set; } public string GetIdentifierForItem(Information information) { string identifier = null; string name = information.TargetName; // Iterating through the Windowtypes // searching the 'Name' and then return its ID foreach (var windowType in WindowTypes) { if (name ==

Caliburn Micro -> Composing Views from multiple Views/UserControls/CustomControls

柔情痞子 提交于 2019-12-03 20:38:48
How is it possible to re-use and compose parts in CM managed windows? I have found posts regarding using two UserControls to bind to the same ViewModel, but not so much if I want to have multiple views and viewmodels all composed in the same window. (a viewmodel for each view composed into a "master view") The first part of my question would be how to break up components for re-use? If I have two areas of a window where one is a datagrid and another is a details view with labels and text boxes should these be in separate usercontrols, customcontrols or windows? Each one would ideally be stand

Register custom file type with custom UI editor in Visual Studio 2010

筅森魡賤 提交于 2019-12-03 16:44:46
I found old article called LearnVSXNow and part #30 - Custom Editors in Visual Studio . There is sample project The Blog Item Editor which shows how to make custom file type assigned with custom UI editor for this file type extension (.blit) This sample uses project VSXtra , which is written for Visual Studio 2008 . Can someone point me to some tutorial, how-to, or something how to do the same for Visual Studio 2010 ? My goal is to register custom file type extension (e.g. *.myext1) within visual studio 2010, and assign my own custom UI designer (WinForms, derived from UserControl) to handle

Change Dll loaded with MEF

柔情痞子 提交于 2019-12-03 16:39:49
I'm using MEF and the System.ComponentModel.Composition.dll to load some dll. I'm doing something like : AggregateCatalog catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()), new DirectoryCatalog(directory)); _container = new CompositionContainer(catalog); _container.ComposeParts(this); to import my dll. After some times, I would like to update my dll but if I try to delete it, I have an access denied, because it's alrealdy used by the program. How can I release the dll, replace with a new dll and load the dll again ? (without closing the program) Thanks in

export generics in MEF

﹥>﹥吖頭↗ 提交于 2019-12-03 16:27:00
问题 I want to export a generic class to a generic interface via MEF. My objects are: public interface IService<T> { } [Export(typeof(IService<T>))] // error!!!!!! public class Service<T> { } public class Client<T> { [Import] private IService<T> _service; } But when I try to export IService<T> , I get this error: Attribute argument cannot use type parameters Can anybody guide me to do this please? 回答1: Try [Export(typeof(IService<>))] To get a generic type definition from the typeof operator, you

How to export & import functions and execute them with MEF?

◇◆丶佛笑我妖孽 提交于 2019-12-03 16:03:04
问题 I am creating an application that imports several plugins. I need the ability to execute functions that are implemented in each of the plugins. For example, I need to do something like this. ///////////////////////////////////////////////////////////////////////////////// MainApp: [ImportMany(?)] public IEnumerable<Lazy<?>> PluginFunctions1 { get; set; } [ImportMany(?)] public IEnumerable<Lazy<?>> PluginFunctions2 { get; set; } foreach (f1 in PluginFunctions1) { f1(); // execute Function1

How to prioritize different catalogs in MEF?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 15:35:08
I have a AggregateCatalog that contains an AssemblyCatalog and a DirectoryCatalog. I want them to work like this: If both catalogs can find an export, choose the one from the DirectoryCatalog. If neither of them can find an export, then just leave the import to be null. If only one of them can find an export, then just use that export to fill the import. How can I achieve something like this? You can achieve point 1. and 3. by putting the catalogs in different export providers, and then passing the export providers to the CompositionContainer constructor in order of priority like this: var