TylerBrinks/Snap — Issue #16: RegisterInterceptor<Foo> is unknown method on IAspectConfiguration
Author: rwgeorge
Created: 2011-10-14 19:06:20+00:00
State: open

I have this code:

SnapConfiguration.For<StructureMapAspectContainer>(c =>
{
c.IncludeNamespace("MyCompany.MyProgram*");
//c.Bind<IncludeLoggingInterceptor>().To<IncludeLoggingAttribute>();
c.RegisterInterceptor<IncludeLoggingInterceptor>();
});

Visual Studio is yelling at me that RegisterInterceptor is not a known method on IAspectConfiguration ... and it's right! I can't find that method. So, that may be a problem (at least with the docs).

Let me explain what I'm trying to do and maybe someone can help me (because it is not working for me):

I have an enterprise application that uses MVC3 with StructureMap as its default dependency resolver. I employ the repository pattern with a unit of work. I'm using the ObjectFactory.Intialize approach to configureing StructureMap. Here's the config I think I want (but isn't working):

public static class IoC
{
public static IContainer Initialize()
{
SnapConfiguration.For<StructureMapAspectContainer>(c =>
{
c.IncludeNamespace("MyCompany.MyProgram");
c.Bind<IncludeLoggingInterceptor>().To<IncludeLoggingAttribute>();
c.RegisterInterceptor<IncludeLoggingInterceptor>();
//c.Scan(s => s.ThisAssembly().WithDefaults());
//c.AllAspects().KeepInContainer();
});

ObjectFactory.Initialize(x =>
{
x.For<IControllerActivator>().Use<StructureMapControllerActivator>();
x.For<DbContext>().HybridHttpOrThreadLocalScoped().Use<LogixDataContext>();
x.For<IUnitOfWork>().HybridHttpOrThreadLocalScoped().Use<EfUnitOfWork>();
x.For(typeof(IRepository<>)).Use(typeof(RepositoryBase<>));

x.Scan(scan =>
{
scan.ExcludeNamespaceContainingType();
scan.ExcludeNamespaceContainingType();
scan.AssembliesFromApplicationBaseDirectory();
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.AddAllTypesOf();
});
});

return ObjectFactory.Container;
}
}

When I use the IncludeLogging Attribute in one of my controllers (which is injected by StructureMap via MVC3's DependencyResolver) nothing happens - as in, my interceptor is not invoked. I really want to learn how to configure like this. Is there anyone (please) who has experience with non-trivial configurations for Snap with StructureMap? Thanks!

Best,
Bob