mef

Template 10 dependency injection using MEF

落花浮王杯 提交于 2019-12-12 03:49:46
问题 I'm familiar with using MEF in .NET Framework 4.6.* but not in .NET Core. I'm messing about with the Hamburger template from Template 10 to see if it is suitable for my needs but I haven't been able to figure out how to compose my view models using MEF. My question is how can I navigate to a view using the navigation service in such a way that its view model will be injected by MEF? 回答1: I have one way of getting this working but it seems a bit code smelly so better answers are welcomed. I

composing MEF parts in C# like a simple Funq container

冷暖自知 提交于 2019-12-12 03:48:15
问题 In Funq and probably most other IoC containers I can simply do this to configure a type: container.Register<ISomeThing>(c => new SomeThing()); How could I quickly extend MEF (or use existing MEF functionality) to do the same without using attributes. Here is how I thought I could do it: var container = new CompositionContainer(); var batch = new CompositionBatch(); batch.AddExport<ISomeThing>(() => new SomeThing()); batch.AddExportedValue(batch); container.Compose(batch); With this extension

Default constructor and open generics in MEF 2 using conventions

青春壹個敷衍的年華 提交于 2019-12-12 03:37:47
问题 I am trying to use MEF 2 in my project, I usually use SimpleInjector but this time I wanted to try MEF. My main problem is dealing with open generics, this is what i got so far public interface ISetting {} public class Setting : ISetting {} public interface ILogger<TLog> { TLog Fetch() } public class Logger<TLog> : ILogger<TLog> { private ISetting settings; public Logger(ISetting settings) { this.settings = settings; } public TLog Fetch() { return default(TLog); } } Now for the container part

MEF With Portable Class library using Microsoft Composition MEF2 throws file not found exception

浪子不回头ぞ 提交于 2019-12-12 02:53:16
问题 I am working on Portable Class Library(PCL) and trying to achieve MEF in that. I used System.Composition from Nuget. When i build and package for vsix (Extension for Visual Studio) it doesn't package and place those dll's to extension folder (C:\Users\UserName\AppData\Local\Microsoft\VisualStudio\14.0Exp\Extensions\ExtensionName\AppName\versionofYourApp). When i manually place those library in this folder it works fine. Can some one suggest a good solution to this problem. I am writing it for

Using MEF with abstract base class

喜你入骨 提交于 2019-12-12 02:26:06
问题 I'm building a database import app than I want to be extensible (custom db models can be added as needed). My base component has methods that extended types have to implement: MapData & SaveData. I defined the base as an abstract class, and everything works when the extended types are in the same namespace. However, I want to use MEF to import extended types in a different namespace at runtime, but I can't figure out how to do that. Base class: namespace Program { public abstract class

Attribute Useage For Checking Method Permissions

自古美人都是妖i 提交于 2019-12-12 02:22:52
问题 I'm trying to implement a security mechanism to automatically test a particular plugins permissions and method security privileges and I've gotten a bit stuck on how to get this working. I've writing a custom MEF Metadata attribute that takes a constructor property like: params PluginPermission[] permission This contains an array of all the permissions that the plugin is granted. The PluginPermission class looks like: PluginPermission.cs public enum PluginPermission { CreateUsers, DeleteUsers

Syntax Highlight doesn't work for IVsInvisibleEditor

我是研究僧i 提交于 2019-12-12 01:28:48
问题 I have created an instance of IVsInvisibleEditor. I've used following code to achieve this: public IWpfTextViewHost CreateEditor(string targetFile) { var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)); var editorAdapter = componentModel.GetService<IVsEditorAdaptersFactoryService>(); var editorFactoryService = componentModel.GetService<ITextEditorFactoryService>(); var invisibleEditorManager = (IVsInvisibleEditorManager

Localisation issue while dynamically loading the WPF DLLs using MEF

梦想的初衷 提交于 2019-12-12 00:53:17
问题 I am trying to dynamically load DLLs and I am facing the following issues: The Resources in the dynamically loaded DLLs are not working. It is picking the neutral culture which is English, and no other .resx files are getting called. I am unable to call a WCF service in the dynamically loaded DLLs. For 2) I have a work around but for 1) I am still stuck. The technology i am using is. Net 4.0(with MEF) 回答1: I found an alternate solution for 1). It was my mistake only, the resources DLLs were

Getting Error in No valid exports were found that match the constraint

不羁岁月 提交于 2019-12-11 23:09:40
问题 While running the following Program i am getting the The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information. 1) No valid exports were found that match the constraint '((exportDefinition.ContractName == "System.Collections.Generic.IEnumerable(MEF.IToolWindow)") AndAlso (exportDefinition

How to bind data from View to UserControl with SoapBox

主宰稳场 提交于 2019-12-11 14:28:39
问题 I have my SoapBox.Document 'Register' [Export(SoapBox.Core.ExtensionPoints.Workbench.Documents, typeof(IDocument))] [Export(CompositionPoints.Workbench.Documents.Register, typeof(Register))] [Document(Name = DOC_NAME)] class Register : AbstractDocument { public Receipt actualReceipt; private const string DOC_NAME = "Register"; public Register() { Name = DOC_NAME; Title = "Recipe Document Title"; SomeProperty = "Hello from the recipe document!"; } } In this Document I want to user UserControls