ServiceRegistrator
class ServiceRegistrator
using System;
using System.Linq;
namespace Stashbox.Registration
{
internal class ServiceRegistrator
{
public void Register(IContainerContext containerContext, ServiceRegistration serviceRegistration, Type serviceType)
{
if (serviceRegistration.RegistrationContext.AdditionalServiceTypes.Any()) {
foreach (Type additionalServiceType in serviceRegistration.RegistrationContext.AdditionalServiceTypes) {
Register(containerContext, serviceRegistration, additionalServiceType, serviceRegistration.RegistrationContext.ReplaceExistingRegistration);
}
}
Register(containerContext, serviceRegistration, serviceType, serviceRegistration.RegistrationContext.ReplaceExistingRegistration);
}
public void Register(IContainerContext containerContext, ServiceRegistration serviceRegistration, Type serviceType, bool replace)
{
if (serviceRegistration.IsDecorator) {
containerContext.DecoratorRepository.AddDecorator(serviceType, serviceRegistration, false, replace);
containerContext.RootScope.InvalidateDelegateCache();
} else
containerContext.RegistrationRepository.AddOrUpdateRegistration(serviceRegistration, serviceType, false, replace);
if (replace)
containerContext.RootScope.InvalidateDelegateCache();
}
public void ReMap(IContainerContext containerContext, ServiceRegistration serviceRegistration, Type serviceType)
{
if (serviceRegistration.RegistrationContext.AdditionalServiceTypes.Any()) {
foreach (Type additionalServiceType in serviceRegistration.RegistrationContext.AdditionalServiceTypes) {
ReMap(containerContext, serviceRegistration, additionalServiceType, serviceRegistration.RegistrationContext.ReplaceExistingRegistration);
}
}
ReMap(containerContext, serviceRegistration, serviceType, serviceRegistration.RegistrationContext.ReplaceExistingRegistration);
}
public void ReMap(IContainerContext containerContext, ServiceRegistration serviceRegistration, Type serviceType, bool replace)
{
if (serviceRegistration.IsDecorator)
containerContext.DecoratorRepository.AddDecorator(serviceType, serviceRegistration, true, replace);
else
containerContext.RegistrationRepository.AddOrUpdateRegistration(serviceRegistration, serviceType, true, replace);
containerContext.RootScope.InvalidateDelegateCache();
}
}
}