Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generic registration instead of reflection #555

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

namespace Castle.Windsor.Extensions.DependencyInjection.Extensions
{
using System.Reflection;

using Castle.MicroKernel.Registration;

public static class ServiceDescriptorExtensions
Expand All @@ -26,11 +24,8 @@ public static IRegistration CreateWindsorRegistration(this Microsoft.Extensions.
{
return RegistrationAdapter.FromOpenGenericServiceDescriptor(service);
}
else
{
var method = typeof(RegistrationAdapter).GetMethod("FromServiceDescriptor", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(service.ServiceType);
return method.Invoke(null, new object[] { service }) as IRegistration;
}

return RegistrationAdapter.FromServiceDescriptor(service);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ public static IRegistration FromOpenGenericServiceDescriptor(Microsoft.Extension
.IsDefault();
}

public static IRegistration FromServiceDescriptor<TService>(Microsoft.Extensions.DependencyInjection.ServiceDescriptor service) where TService : class
public static IRegistration FromServiceDescriptor(Microsoft.Extensions.DependencyInjection.ServiceDescriptor service)
{
var registration = Component.For<TService>()
var registration = Component.For(service.ServiceType)
.NamedAutomatically(UniqueComponentName(service));

if(service.ImplementationFactory != null)
if (service.ImplementationFactory != null)
{
registration = UsingFactoryMethod<TService>(registration, service);
registration = UsingFactoryMethod(registration, service);
}
else if(service.ImplementationInstance != null)
else if (service.ImplementationInstance != null)
{
registration = UsingInstance<TService>(registration, service);
registration = UsingInstance(registration, service);
}
else if(service.ImplementationType != null)
else if (service.ImplementationType != null)
{
registration = UsingImplementation<TService>(registration, service);
registration = UsingImplementation(registration, service);
}

return ResolveLifestyle<TService>(registration, service)
return ResolveLifestyle(registration, service)
.IsDefault();
}

Expand Down