Could someone help me understand the following issue, this may be a bug or I misunderstand IConfigureComponents
usage. If you take a look at the example below, when I register my auto mapper with IConfigureComponents.ConfigureComponent
I am getting an System.OutOfMemoryException
when attempting to create the mapper (I’ve removed the mapping code for brevity).
However when I pre-register the mapper in the container, I don’t experience the same issue. Would really appreciate some help understanding this issue.
Registration with IConfigureComponents (NOT WORKING)
private static EndpointConfiguration ConfigureDependencies(this EndpointConfiguration endpointConfiguration, UnityContainer container)
{
endpointConfiguration.UseContainer<UnityBuilder>(
customizations: customizations =>
{
customizations.UseExistingContainer(container);
});
endpointConfiguration.RegisterComponents(configureComponents =>
{
configureComponents.ConfigureComponent<MutateIncomingMessages>(DependencyLifecycle.SingleInstance);
configureComponents.ConfigureComponent(delegate() { return new MapperConfiguration(cfg =>
{
// Mappings
}).CreateMapper();
}, DependencyLifecycle.SingleInstance);
});
return endpointConfiguration;
}
public class MutateIncomingMessages : IMutateIncomingMessages
{
private IMapper _mapper;
public MutateIncomingMessages(IMapper mapper)
{
_mapper = mapper;
}
}
Prior registration in container (WORKING)
private static EndpointConfiguration ConfigureDependencies(this EndpointConfiguration endpointConfiguration, UnityContainer container)
{
container.RegisterInstance<IMapper>(new MapperConfiguration(cfg =>
{
// Mappings
}).CreateMapper());
endpointConfiguration.UseContainer<UnityBuilder>(
customizations: customizations =>
{
customizations.UseExistingContainer(container);
});
endpointConfiguration.RegisterComponents(configureComponents =>
{
configureComponents.ConfigureComponent<MutateIncomingMessages>(DependencyLifecycle.SingleInstance);
})
return endpointConfiguration;
}
public class MutateIncomingMessages : IMutateIncomingMessages
{
private IMapper _mapper;
public MutateIncomingMessages(IMapper mapper)
{
_mapper = mapper;
}
}