Last active
March 8, 2018 10:32
-
-
Save molinch/5386ee5c0ed56e4ccc39ab0b8757ca58 to your computer and use it in GitHub Desktop.
Portable MEF / ExportFactory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Composition; | |
using System.Composition.Hosting; | |
using System.Reflection; | |
namespace ConsoleApp6 | |
{ | |
public interface IFu {} | |
[Export(typeof(IFu)), Shared] | |
public class Fu: IFu {} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var container = new ContainerConfiguration().WithAssembly(typeof(Program).GetTypeInfo().Assembly).CreateContainer(); | |
var fu0 = container.GetExport<ExportFactory<IFu>>().CreateExport().Value; | |
var fu1 = container.GetExport<ExportFactory<IFu>>().CreateExport().Value; | |
var areSame = ReferenceEquals(fu0, fu1); // it is true now, but with older MEF it was false | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment