Intent Compositor
Intent Compositor is an open source Aspect Oriented Programming style framework designed to simplify object composition and provide an OOP-complete paradigm for multiple inheritance in C#. Composition is defined via Attributes and the framework then wires everything together. Generated code is saved to a partial class at design time without any 'magic' so your code base maintains its portability.
Using Intent Compositor
//An interface representing a common chunk of code:
public interface IPrettyPrint{
string PrettyPrint();
}
//A reusable implementation of IPrettyPrint
public class PrettyPrinter : IPrettyPrint,
//Required interface to support IntentCompositor
IIntentResolver<IPrettyPrint, ICriteria>
{
private ICriteria _target;
public IPrettyPrint Initialize(ICriteria target){
_target = target;
return this;
}
public string PrettyPrint(){
return string.Format("*****\r\n{0} printed at {1}******\r\n",
_target.GetType().FullName, DateTime.Now);
}
}
//A sample composite class using Intent Compositor
[SatisfyIntent(Intent = typeof(IPrettyPrint),
Resolver = typeof(PrettyPrinter)]
public partial class SampleClass(){}
//Partial class generated by Intent Compositor
public partial class SampleClass() : IPrettyPrint, ICriteria
{
public string PrettyPrint(){
(new PrettyPrinter() as IPrettyPrint)
.Initialize(this as ICriteria)
.PrettyPrint();
}
}
Installing Intent Compositor
The Intent Compositor Code Generator is installed as a Visual Studio plug-in available in the Visual Studio Gallery, either inside Visual Studio or on the web here.Installing the plug-in installs the Intent Compositor Code Generator and adds a new Code Template, Intent Compositor Class File available in the C# menu.
The Intent Compositor Class File is a standard C# file configured to use the Intent Compositor Code Generator (as can be seen in the Properties window). Adding one to a Project for the first time additionally installs the Intent Compositor nuget package which contains the Attributes used by the Intent Compositor Code Generator. Because of this, developers that don't have the Intent Compositor plug-in installed can continue to work in your code base and any custom build / deployment processes will be unaffected.
Extending Intent Compositor
There are several publicly available extensions for the Intent Compositor which contain common Intents and Resolvers to help you make the most of the Intent Compositor. Take a look at the Intent Compositor Extensions page.Further Reading - Deep Dive
- Intent Compositor - FAQ
- Inspiration for Intent Compositor - http://stackoverflow.com/questions/15452377/c-sharp-object-composition-removing-boilerplate-code
- More....to....come