You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 2, 2020. It is now read-only.
Acoustic edited this page Sep 14, 2010
·
4 revisions
Configuring Snap with Autofac
Dependency
Version
Snap
Current
Snap.Autofac.dll
Current
Autofac.dll
v2.1.13.x
Configuration
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>();
}