Saturday, June 22, 2013

Intent Compositor - The Composition Generator Framework

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

Thursday, June 20, 2013

Intent Compositor - The Compositon Generator Framework - FAQ

Is the Intent Compositor free / open source?

Yes, yes it is!  Intent Compositor can be used freely and is licensed under the Apache Open Source License.  Additionally, it is open source.  Once I'm finished cleaning up the source code it will be available in github.

If I install the Intent Compositor will my teammates be able to build our Solution?

Yes!  Installing the Intent Compositor Visual Studio plug-in will add the Intent Compositor nuget package to your project.  The nuget package includes all class references, which means anyone else using your project (including custom build / deployment scripts) will be unaffected.  Additionally, as all code is generated into a partial class at design time the generated code is completely portable.

My Project needs to be Signed.  Can I still use Intent Compositor?

Yes!  All Intent Compositor assemblies are signed and can be safely referenced in your project.

What are the minium requirements to use Intent Compositor?

The Intent Compositor Visual Studio plug-in requires Visual Studio 2012.  The Intent Compositor assembly targets .NET 3.5.

I found a bug!  I have a suggestion!

Feedback, comments, bug reports?  Email me at CopaceticSoftware at gmail.com! 

Intent Compositor Extensions

  • IntentCompositor.log4net - Provides the [HaveLogger] attribute which quickly adds a log4net ILog instance to a composite class.  Stop typing "LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType)"!!
  • IntentCompositor.Repository - Provides common Intents for Repositories such as IGetByID, IContains, IAdd, IUpdate and IDelete.  Includes the InMemoryRepositoryResolver for easy unit testing.
  • IntentCompositor.Repository.Sql - Provides the SqlStoredProcedureResolver which can Resolve all Intents defined in IntentCompositor.Repository using a Sql Server and Stored Procedures.  Get your Sql based repositories up and running in no time!