Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Using Castle

Acoustic edited this page Sep 14, 2010 · 4 revisions

Configuring Snap with Castle

Dependency Version
Snap Current
Snap.CastleWindsor.dll Current
Castle.Core.dll v1.2.0.x
Castle.MicroKernel.dll v2.1.0.x
Castle.Windsor.dll v2.1.0.x

Configuration

Castle uses the concept of a container as to create object instances. Because containers are instantiated objects, it’s necessary to use Snap’s instance-based fluent configuration.

// Create a container
var container = new WindsorContainer();
// Configure Snap to use Castle using the container instance
SnapConfiguration.For(new CastleAspectContainer(container.Kernel)).Configure(c =>
{
    c.IncludeNamespaceRoot("My.Namespace.Root");
    //c.IncludeNamespace("My.Namespace*");
    c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>();
});

Castle is now fully configured to build proxied instances that will run your configured interceptors.

// Register your own types with the Castle kernel.
container.AddComponent("MyType", typeof (IMyType), typeof (MyType));
// Get an AoP wrapped instance of your type from Castle
var instance = (IMyType)container.Kernel[typeof(IMyType)];

Happy coding!