Skip to content

smudge202/compose

 
 

Repository files navigation

Compose

Join the chat at https://gitter.im/compose-net/compose

Latest Release NuGet

Build status Stories in Backlog Stories in Ready Stories in Progress

Description

Compose is a lightweight framework to assist in application composition, enforcing clean and efficient component isolation, whilst providing key features out of the box.

Compose follows the same OWIN composition patterns as found in the MVC 6 samples, but on a broader basis, minimising dependencies and providing consistent patterns across all application types, from ASP.Net MVC, to Console Applications.

Getting Started

Prerequisites

  • .Net 4.5.2 or higher

Install Compose

Includes built-in support for Dependency Injection, Transitioning, Snapshotting, and basic Executable Applications.

To install Compose, run the following command in the Package Manager Console

PM> Install-Package Compose -Pre

Basic Usage

Features

Dependency Injection

There are a myriad of DI Containers available nowadays such as Autofac, Castle Windsor, Ninject, StructureMap, Unity, etc.

As part of ASP.Net vNext development, Microsoft are releasing an Open Source Dependency Injection Framework that supports all of the popular existing containers listed above.

We utilise this new framework so that, unless you need additional features provided by Compose, your services only require a dependency on the Microsoft.Framework.DependencyInjection package.

Transitioning

One of the key features Compose provides is the ability to seamlessly switch your service implementations at runtime. No additional code or changes are required in your service extensions, simply tag the service(s) as Transitional during composition.

For example:

app.UseServices(services => 
{
	services
		.AddYourServices()
		// Mark one of the interfaces added by your service as transitional
		.WithTransitional<IDependency>();
});
// So long as an interface is regsitered as transitional, you can change it at any stage using
app.Transition<IDependency, MyReplacementDependency>();

Snapshotting

This feature allows your application to better manage dependencies, particularly those for which your application is not responsible. For example, you may transition an interface from a service extension without any knowledge of how the interface is implemented. Snapshotting allows you to Rollback the dependency graph to use the original implementation, without the need to reference it directly.

app.UseServices(services =>
{
	services
		.AddSomeServices()
		// Mark all interfaces as transitional
		.AsTransitional();
});
// app.Snapshot() is called for you by UseServices, but you can
// call it at any stage to overwrite the existing snapshot.

// Transition a component to your own implementation
app.Transition<IDependency, MyReplacementDependency>();
// When you want to transition back to the original service
app.Restore(); 

FAQ / Troubleshooting

-Q. How to debug/view the code emitted? -A. Add the ENABLE_SAVE_DYNAMIC_ASSEMBLY compilation symbol to the Compose build to have the dyanmic assemblies stored in the execution directory.

About

Lightweight framework to assist in application composition

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.1%
  • Batchfile 0.9%