| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | namespace IceRpc.Extensions.DependencyInjection.Internal; |
| | 4 | |
|
| | 5 | | /// <summary>Implements <see cref="IInvokerBuilder" /> for Microsoft's DI container.</summary> |
| | 6 | | internal sealed class InvokerBuilder : IInvokerBuilder |
| | 7 | | { |
| 6 | 8 | | public IServiceProvider ServiceProvider { get; } |
| | 9 | |
|
| | 10 | | private bool _isIntoCalled; |
| | 11 | |
|
| 6 | 12 | | private readonly Pipeline _pipeline = new(); |
| | 13 | |
|
| | 14 | | public IInvokerBuilder Into(IInvoker invoker) |
| 6 | 15 | | { |
| 6 | 16 | | _ = _pipeline.Into(invoker); |
| 6 | 17 | | _isIntoCalled = true; |
| 6 | 18 | | return this; |
| 6 | 19 | | } |
| | 20 | |
|
| | 21 | | public IInvokerBuilder Use(Func<IInvoker, IInvoker> interceptor) |
| 8 | 22 | | { |
| 8 | 23 | | _ = _pipeline.Use(interceptor); |
| 8 | 24 | | return this; |
| 8 | 25 | | } |
| | 26 | |
|
| 12 | 27 | | internal InvokerBuilder(IServiceProvider provider) => ServiceProvider = provider; |
| | 28 | |
|
| | 29 | | internal IInvoker Build() => |
| 6 | 30 | | _isIntoCalled ? _pipeline : |
| 6 | 31 | | throw new InvalidOperationException( |
| 6 | 32 | | $"The configure action on the {nameof(IInvokerBuilder)} must include a call to {nameof(Into)}."); |
| | 33 | | } |