Skip to content

Instantly share code, notes, and snippets.

@pawelpabich
Last active December 27, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawelpabich/7408127 to your computer and use it in GitHub Desktop.
Save pawelpabich/7408127 to your computer and use it in GitHub Desktop.
builder.RegisterAssemblyTypes(thisAssembly)
.Where(type => type.Implements<IToResolve>())
.AsImplementedInterfaces()
.InstancePerLifetimeScope()
// What is the name of MyCustomRegistrationCallback in AutoFac lingo?
// Does it even exist?
.MyCustomRegistrationCallback(data =>
{
if (data.Type == typeof (ThisOneType))
{
data.Registration.EnableInterfaceInterceptors();
}
})
@HEskandari
Copy link

public class InterceptionRegistrationSource : IRegistrationSource
{
    public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Func<Service, IEnumerable<IComponentRegistration>> registrationAccessor)
    {
        var typedService = service as IServiceWithType;
        if (typedService != null && 
            typedService.ServiceType.IsClass && 
            typedService.ServiceType == typeof(ThisOneType))
        {
            yield return RegistrationBuilder.ForDelegate((context, parameters) =>
            {
                var serviceInstance = context.Resolve(typedService.ServiceType);
                //resolve or change registerations, via context etc.
                return serviceInstance;
            }).As(typedService.ServiceType)
                .CreateRegistration();
        }
    }

    public bool IsAdapterForIndividualComponents { get { return false; } }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment