Using Autofac - TylerBrinks/Snap GitHub Wiki
| Dependency | Version |
| Snap | Current |
| Snap.Autofac.dll | Current |
| Autofac.dll | v2.1.13.x |
Autofacuses the concept of a container builder to create object instances. Because the container builder is an instantiated object, it’s necessary to use Snap’s instance-based fluent configuration.
// Create an Autofac ContainerBuilder
var builder = new ContainerBuilder();
// Configure Snap with the builder instance
SnapConfiguration.For(new AutofacAspectContainer(builder)).Configure(c =>
{
c.IncludeNamespaceRoot("My.Namespace.Root");
// or c.IncludeNamespace("My.Namespace*");
c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>();
});
Autofac is now fully configured to build proxied instances that will run your configured interceptors.
// Register your own types with the Autofac builder.
builder.Register(r => new MyType()).As<IMyType>();
// Get an AoP wrapped instance of your type from Ninject
using (var container = builder.Build())
{
var instance = container.Resolve<IMyType>();
}
Happy coding!