Skip to content

Instantly share code, notes, and snippets.

@NatMarchand
Created May 4, 2018 12:02
Show Gist options
  • Save NatMarchand/79a80651b47742ed42e6782c9f6ff847 to your computer and use it in GitHub Desktop.
Save NatMarchand/79a80651b47742ed42e6782c9f6ff847 to your computer and use it in GitHub Desktop.
webformdependencyinjection_autofac2
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Autofac.Builder;
using Autofac.Core;
namespace Autofac.Integration.Web
{
public class WebFormRegistrationSource : IRegistrationSource
{
public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Func<Service, IEnumerable<IComponentRegistration>> registrationAccessor)
{
if (service is IServiceWithType serviceWithType && serviceWithType.ServiceType.Namespace.StartsWith("ASP", true, CultureInfo.InvariantCulture))
{
return new[]
{
RegistrationBuilder.ForType(serviceWithType.ServiceType).CreateRegistration()
};
}
return Enumerable.Empty<IComponentRegistration>();
}
public bool IsAdapterForIndividualComponents => true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment