Code Monkey home page Code Monkey logo

mefgeneric's Introduction

Junil Um
http://blog.powerumc.kr

Introduction

MEFGeneric is a framework to support CLR Generic types in MEF (Managed Extensibility Framework).

This is require Mef Framework if you need code on .NET Framework 3.0 or C# 2.0 under.

Background

MEF does not support open generic types. Therefore, open generic type classes cannot utilize MEF Composition. But, via MEFGeneric, changing and/or extending current MEF source code allows use of open generic types in MEF.

###Example

The following source code does not work in MEF, but using MEFGeneric, you can resolve and compose objects.

Catalog and Composition

var catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
var genericCatalog = new GenericCatalog(catalog);
var container = new CompositionContainer(genericCatalog);

// Export Definition
public interface IUMC<T>
{
  void Say();
}

// Important : via only MEFGeneric, you can export definition of IUMC<> generic types.
[Export(typeof(IUMC<>))]
public class UMC<T> : IUMC<T>
{
	#region IUMC<T> Member

	public void Say()
	{
		Console.WriteLine(typeof(T).FullName);
	}

	#endregion
}

Container Resolving / Injection

container.GetExportedValueOrDefault<IUMC<int>>().Say();
container.GetExportedValueOrDefault<IUMC<string>>().Say();

mefgeneric's People

Contributors

powerumc avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

bubdm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.