On the heels of the Ninject 2.0 release, I am happy to announce the release of the Ninject Interception Extension 2.0. This release provides API backward compatibility for the 1.5 version as well as new method interception, enhanced binding syntax, automatic property changed notification, as well as support for Castle DynamicProxy 2.2 and LinFu DynamicProxy. I will be writing a follow up post about the new features and usage patterns.
I want to thank Krzysztof Koźmic for his help with the Castle DynamicProxy 2.2 integration and Michael Hart for letting me merge his Ninject 1.5 method interception code into the new extension.
You will find downloads on the GitHub dowload page for .NET 3.5, Silverlight 3, and Mono 2.0. For those using automatic module loading or only want to use one DynamicProxy dependency without worrying about delay loading, there are three .NET 3.5 downloads: Castle+LinFu, Castle, and LinFu. Go get it!
I have been playing with the Ninject conventions binding extension syntax and usage model. It was originally based on the StructureMap assembly scanner, but I want to use the API in a different fashion.
I have been working on making the API more like LINQ in the way you think and use it. Here is a sampling of the new API that I am testing. Remember, you would never bind like this, ideally you would set up a few different scans to bind everything the way you want it.
IKernel kernel = new StandardKernel();
kernel.Scan(
x =>
{
// set up the source collection of types to process
x.FromCallingAssembly();
x.From( from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetExportedTypes()
select type );
x.FromAssemblyContaining<IGenericView>();
x.FromAssembliesInPath( "." );
x.FomAssembliesMatching( "*.Model.dll" );
x.FromAssemblyContaining(new[] {typeof (IGenericView), typeof (StringView)});
// Filter out what you want
x.Where( type => !type.IsAbstract );
x.WhereTypeIsInNamespace( "Base.Model" );
x.WhereTypeIsInNamespaceOf<StringView>();
x.WhereTypeIsNotInNamespace( "Base.Test" );
x.WhereTypeIsNotInNamespaceOf<StandardKernel>();
x.WhereTypeInheritsFrom<IGenericView>();
// Exclude items even if they match your Where criteria
x.Excluding<INinjectSettings>();
x.Excluding( new[] {typeof (IServiceProvider), typeof (IInitializable)} );
// Include items whether or not they match your Where criteria
x.Including<DefaultView>();
// Tell the scanner how to determine bindings
x.BindWithDefaultConventions();
// Declare the binding scope for scanned members
x.InTransientScope();
} );
Some API calls will not be available on all platforms due to security restrictions of course.