Skip to content

Commit

Permalink
adjust EndpointSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard-dumitru committed Jul 31, 2024
1 parent 5fdca6d commit aa58a23
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.BackCompat/ServiceHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ServiceHostBuilder(IServiceProvider serviceProvider)
public ServiceHostBuilder AddEndpoint(EndpointSettings settings)
{
settings = settings.WithServiceProvider(_serviceProvider);
Endpoints.Add(settings.Name, settings);
Endpoints.Add(settings.ContractType.Name, settings);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc/Extensibility/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TProxy GetProxy<TProxy>() where TProxy : class

internal void ValidateInternal()
{
var haveDeferredInjectedCallbacks = Callbacks?.Any(x => !x.Service.HasServiceProvider() && x.Service.MaybeGetInstance() is null) ?? false;
var haveDeferredInjectedCallbacks = Callbacks?.Any(x => x.Service.MaybeGetServiceProvider() is null && x.Service.MaybeGetInstance() is null) ?? false;

if (haveDeferredInjectedCallbacks && ServiceProvider is null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/UiPath.CoreIpc/Helpers/Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ internal abstract record ServiceFactory
public virtual ServiceFactory WithProvider(IServiceProvider? serviceProvider) => this;

internal virtual object? MaybeGetInstance() => null;
internal virtual bool HasServiceProvider() => false;
internal virtual IServiceProvider? MaybeGetServiceProvider() => null;

public sealed record Injected : ServiceFactory
{
public required IServiceProvider ServiceProvider { get; init; }

internal override bool HasServiceProvider() => ServiceProvider is not null;
internal override IServiceProvider? MaybeGetServiceProvider() => ServiceProvider;

public override IDisposable? Get(out object service)
{
Expand Down
13 changes: 7 additions & 6 deletions src/UiPath.CoreIpc/Server/ServiceHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

public record EndpointSettings
{
internal TaskScheduler? Scheduler { get; set; }
public TaskScheduler? Scheduler { get; set; }
public BeforeCallHandler? BeforeCall { get; set; }
public Type ContractType => Service.Type;
public object? ServiceInstance => Service.MaybeGetInstance();
public IServiceProvider? ServiceProvider => Service.MaybeGetServiceProvider();
internal ServiceFactory Service { get; }

internal string Name => Service.Type.Name;

public EndpointSettings(Type contractType, object? serviceInstance) : this(
serviceInstance is not null
? new ServiceFactory.Instance()
Expand Down Expand Up @@ -42,20 +43,20 @@ public void Validate()
}
}

protected internal virtual EndpointSettings WithServiceProvider(IServiceProvider serviceProvider)
public virtual EndpointSettings WithServiceProvider(IServiceProvider serviceProvider)
=> new EndpointSettings(Service.Type, serviceProvider)
{
BeforeCall = BeforeCall,
Scheduler = Scheduler
};
}

public record EndpointSettings<TContract> : EndpointSettings where TContract : class
public sealed record EndpointSettings<TContract> : EndpointSettings where TContract : class
{
public EndpointSettings(TContract? serviceInstance = null) : base(typeof(TContract), serviceInstance) { }
public EndpointSettings(IServiceProvider serviceProvider) : base(typeof(TContract), serviceProvider) { }

protected internal override EndpointSettings WithServiceProvider(IServiceProvider serviceProvider)
public override EndpointSettings WithServiceProvider(IServiceProvider serviceProvider)
=> new EndpointSettings<TContract>(serviceProvider)
{
BeforeCall = BeforeCall,
Expand Down

0 comments on commit aa58a23

Please sign in to comment.