Skip to content

Commit

Permalink
Fixed MassTransit#4397. Delegate IncludeInConfigureEndpoints on Endpo…
Browse files Browse the repository at this point in the history
…intRegistration
  • Loading branch information
NooNameR authored and phatboyg committed May 23, 2023
1 parent 1d6fc8f commit e450919
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ IActivityRegistrationConfigurator<TActivity, TArguments, TLog> AddActivity<TActi
/// <param name="endpointDefinition">The endpoint definition to add</param>
void AddEndpoint(Type endpointDefinition);

void AddEndpoint<TDefinition, T>(IEndpointSettings<IEndpointDefinition<T>> settings = null)
void AddEndpoint<TDefinition, T>(IRegistration registration, IEndpointSettings<IEndpointDefinition<T>> settings = null)
where TDefinition : class, IEndpointDefinition<T>
where T : class;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace MassTransit.Configuration

public static class DependencyInjectionEndpointRegistrationExtensions
{
public static IEndpointRegistration RegisterEndpoint<TDefinition, T>(this IServiceCollection collection,
public static IEndpointRegistration RegisterEndpoint<TDefinition, T>(this IServiceCollection collection, IRegistration registration,
IEndpointSettings<IEndpointDefinition<T>> settings = null)
where TDefinition : class, IEndpointDefinition<T>
where T : class
{
return RegisterEndpoint<TDefinition, T>(collection, new DependencyInjectionContainerRegistrar(collection), settings);
return RegisterEndpoint<TDefinition, T>(collection, new DependencyInjectionContainerRegistrar(collection), registration, settings);
}

public static IEndpointRegistration RegisterEndpoint<TDefinition, T>(this IServiceCollection collection, IContainerRegistrar registrar,
IEndpointSettings<IEndpointDefinition<T>> settings = null)
IRegistration registration, IEndpointSettings<IEndpointDefinition<T>> settings = null)
where T : class
where TDefinition : class, IEndpointDefinition<T>
{
return new EndpointRegistrar<TDefinition, T>().Register(collection, registrar, settings);
return new EndpointRegistrar<TDefinition, T>(registration).Register(collection, registrar, settings);
}

public static IEndpointRegistration RegisterEndpoint(this IServiceCollection collection, Type endpointDefinitionType)
Expand Down Expand Up @@ -52,11 +52,18 @@ class EndpointRegistrar<TDefinition, T> :
where TDefinition : class, IEndpointDefinition<T>
where T : class
{
readonly IRegistration _registration;

public EndpointRegistrar(IRegistration registration)
{
_registration = registration;
}

public IEndpointRegistration Register(IServiceCollection collection, IContainerRegistrar registrar)
{
collection.TryAddTransient<IEndpointDefinition<T>, TDefinition>();

return registrar.GetOrAdd<IEndpointRegistration>(typeof(T), _ => new EndpointRegistration<T>());
return registrar.GetOrAdd<IEndpointRegistration>(typeof(T), _ => new EndpointRegistration<T>(_registration));
}

public IEndpointRegistration Register(IServiceCollection collection, IContainerRegistrar registrar,
Expand All @@ -66,7 +73,7 @@ public IEndpointRegistration Register(IServiceCollection collection, IContainerR
if (settings != null)
collection.AddSingleton(settings);

return registrar.GetOrAdd<IEndpointRegistration>(typeof(T), _ => new EndpointRegistration<T>());
return registrar.GetOrAdd<IEndpointRegistration>(typeof(T), _ => new EndpointRegistration<T>(_registration));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ public void AddEndpoint(Type definitionType)
_collection.RegisterEndpoint(Registrar, definitionType);
}

public void AddEndpoint<TDefinition, T>(IEndpointSettings<IEndpointDefinition<T>> settings)
public void AddEndpoint<TDefinition, T>(IRegistration registration, IEndpointSettings<IEndpointDefinition<T>> settings)
where TDefinition : class, IEndpointDefinition<T>
where T : class
{
_collection.RegisterEndpoint<TDefinition, T>(Registrar, settings);
_collection.RegisterEndpoint<TDefinition, T>(Registrar, registration, settings);
}

public void AddRequestClient<T>(RequestTimeout timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ public void AddEndpoint(Type endpointDefinition)
_configurator.AddEndpoint(endpointDefinition);
}

public void AddEndpoint<TDefinition, T>(IEndpointSettings<IEndpointDefinition<T>> settings = null)
public void AddEndpoint<TDefinition, T>(IRegistration registration, IEndpointSettings<IEndpointDefinition<T>> settings = null)
where TDefinition : class, IEndpointDefinition<T>
where T : class
{
_configurator.AddEndpoint<TDefinition, T>(settings);
_configurator.AddEndpoint<TDefinition, T>(registration, settings);
}

public void AddRequestClient<T>(RequestTimeout timeout = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public IActivityRegistrationConfigurator ExecuteEndpoint(Action<IEndpointRegistr

configureExecute?.Invoke(configurator);

_configurator.AddEndpoint<ExecuteActivityEndpointDefinition<TActivity, TArguments>, IExecuteActivity<TArguments>>(configurator.Settings);
_configurator.AddEndpoint<ExecuteActivityEndpointDefinition<TActivity, TArguments>, IExecuteActivity<TArguments>>(_registration,
configurator.Settings);

return this;
}
Expand All @@ -48,7 +49,8 @@ public IActivityRegistrationConfigurator CompensateEndpoint(Action<IEndpointRegi

configureCompensate?.Invoke(compensateConfigurator);

_configurator.AddEndpoint<CompensateActivityEndpointDefinition<TActivity, TLog>, ICompensateActivity<TLog>>(compensateConfigurator.Settings);
_configurator.AddEndpoint<CompensateActivityEndpointDefinition<TActivity, TLog>, ICompensateActivity<TLog>>(_registration,
compensateConfigurator.Settings);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public void Endpoint(Action<IEndpointRegistrationConfigurator> configure)

configure?.Invoke(configurator);

_configurator.AddEndpoint<ExecuteActivityEndpointDefinition<TActivity, TArguments>, IExecuteActivity<TArguments>>(configurator.Settings);
_configurator.AddEndpoint<ExecuteActivityEndpointDefinition<TActivity, TArguments>, IExecuteActivity<TArguments>>(_registration,
configurator.Settings);
}

public void ExcludeFromConfigureEndpoints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Endpoint(Action<IEndpointRegistrationConfigurator> configure)

configure?.Invoke(configurator);

_configurator.AddEndpoint<ConsumerEndpointDefinition<TConsumer>, TConsumer>(configurator.Settings);
_configurator.AddEndpoint<ConsumerEndpointDefinition<TConsumer>, TConsumer>(_registration, configurator.Settings);
}

public void ExcludeFromConfigureEndpoints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ public class EndpointRegistration<T> :
IEndpointRegistration
where T : class
{
readonly IRegistration _registration;

public EndpointRegistration(IRegistration registration)
{
_registration = registration;
}

public Type Type => typeof(T);

public bool IncludeInConfigureEndpoints
{
get => true;
get => _registration.IncludeInConfigureEndpoints;
set { }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IFutureRegistrationConfigurator<TFuture> Endpoint(Action<IEndpointRegistr

configure?.Invoke(configurator);

_configurator.AddEndpoint<FutureEndpointDefinition<TFuture>, TFuture>(configurator.Settings);
_configurator.AddEndpoint<FutureEndpointDefinition<TFuture>, TFuture>(_registration, configurator.Settings);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ISagaRegistrationConfigurator<TSaga> Endpoint(Action<IEndpointRegistratio

configure?.Invoke(configurator);

_configurator.AddEndpoint<SagaEndpointDefinition<TSaga>, TSaga>(configurator.Settings);
_configurator.AddEndpoint<SagaEndpointDefinition<TSaga>, TSaga>(_registration, configurator.Settings);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ public async Task Should_exclude_consumer_explicitly()
public async Task Should_exclude_consumer_by_attribute()
{
await using var provider = new ServiceCollection()
.AddMassTransitTestHarness(x =>
{
x.AddConsumer<ExcludedByAttributeConsumer>()
.ExcludeFromConfigureEndpoints();
})
.AddMassTransitTestHarness(x => x.AddConsumer<ExcludedByAttributeConsumer>())
.BuildServiceProvider(true);

var harness = provider.GetTestHarness();
Expand Down
Loading

0 comments on commit e450919

Please sign in to comment.