builder.RegisterType<DescriptiveService>() .As<IDescriptiveService>() .InstancePerHttpRequest();
It's not a pretty sight.
To make this easy to read and, especially with syntax highlighting, relatively easy to spot errors I created a small extension method as part of my dependency configuration class.
public static class DependencyConfig { private static void RegisterPerRequest<TImpl, T>(this ContainerBuilder builder) where TImpl : class, T { builder.RegisterType<TImpl>() .As<T>() .InstancePerHttpRequest(); } public static void Configure(Action<IDependencyResolver> setResolver) { var builder = new ContainerBuilder(); builder.RegisterPerRequest<DescriptiveService,IDescriptiveService>(); // ... } }
I'll grant you that it works better in a wide window or with shorter class names but I'm happy to not be repeating so much code.