Skip to content

Commit

Permalink
Refactoring to a much nicer way of registering both keyed and non key…
Browse files Browse the repository at this point in the history
…ed services at once
  • Loading branch information
MattDavies committed May 27, 2014
1 parent 6d79dff commit f8eea73
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions AutofacContrib.NSubstitute/NSubstituteRegistrationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,8 @@ public IEnumerable<IComponentRegistration> RegistrationsFor
{
if (service == null)
throw new ArgumentNullException("service");

var keyedService = service as KeyedService;
if (keyedService != null)
{
if (!keyedService.ServiceType.IsInterface ||
keyedService.ServiceType.IsGenericType &&
keyedService.ServiceType.GetGenericTypeDefinition() == typeof (IEnumerable<>) ||
keyedService.ServiceType.IsArray ||
typeof (IStartable).IsAssignableFrom(keyedService.ServiceType))
return Enumerable.Empty<IComponentRegistration>();

return new[]
{
RegistrationBuilder.ForDelegate((c, p) => Substitute.For(new[] { keyedService.ServiceType }, null))
.As(service)
.InstancePerLifetimeScope()
.CreateRegistration()
};
}

var typedService = service as TypedService;

var typedService = service as IServiceWithType;
if (typedService == null ||
!typedService.ServiceType.IsInterface ||
typedService.ServiceType.IsGenericType && typedService.ServiceType.GetGenericTypeDefinition() == typeof(IEnumerable<>) ||
Expand Down

0 comments on commit f8eea73

Please sign in to comment.