Add data source
This commit is contained in:
parent
7685e17e80
commit
eeebefee1b
|
|
@ -30,6 +30,8 @@ namespace Microsoft.AspNetCore.Dispatcher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual DispatcherDataSource DataSource { get; set; }
|
||||||
|
|
||||||
public virtual IList<Endpoint> Endpoints
|
public virtual IList<Endpoint> Endpoints
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -56,11 +58,11 @@ namespace Microsoft.AspNetCore.Dispatcher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IChangeToken ChangeToken => NullChangeToken.Singleton;
|
public IChangeToken ChangeToken => DataSource?.ChangeToken ?? NullChangeToken.Singleton;
|
||||||
|
|
||||||
IReadOnlyList<Address> IAddressCollectionProvider.Addresses => _addresses;
|
IReadOnlyList<Address> IAddressCollectionProvider.Addresses => ((IAddressCollectionProvider)DataSource)?.Addresses ?? _addresses ?? (IReadOnlyList<Address>)Array.Empty<Address>();
|
||||||
|
|
||||||
IReadOnlyList<Endpoint> IEndpointCollectionProvider.Endpoints => _endpoints;
|
IReadOnlyList<Endpoint> IEndpointCollectionProvider.Endpoints => ((IEndpointCollectionProvider)DataSource)?.Endpoints ?? _endpoints ?? (IReadOnlyList<Endpoint>)Array.Empty<Endpoint>();
|
||||||
|
|
||||||
public virtual async Task InvokeAsync(HttpContext httpContext)
|
public virtual async Task InvokeAsync(HttpContext httpContext)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Dispatcher
|
||||||
|
{
|
||||||
|
public abstract class DispatcherDataSource : IAddressCollectionProvider, IEndpointCollectionProvider
|
||||||
|
{
|
||||||
|
public abstract IChangeToken ChangeToken { get; }
|
||||||
|
|
||||||
|
protected abstract IReadOnlyList<Address> GetAddesses();
|
||||||
|
|
||||||
|
protected abstract IReadOnlyList<Endpoint> GetEndpoints();
|
||||||
|
|
||||||
|
IReadOnlyList<Address> IAddressCollectionProvider.Addresses => GetAddesses();
|
||||||
|
|
||||||
|
IReadOnlyList<Endpoint> IEndpointCollectionProvider.Endpoints => GetEndpoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Dispatcher
|
||||||
|
{
|
||||||
|
public class SimpleDispatcherDataSource : DispatcherDataSource
|
||||||
|
{
|
||||||
|
private readonly List<Address> _addresses;
|
||||||
|
private readonly List<Endpoint> _endpoints;
|
||||||
|
|
||||||
|
public SimpleDispatcherDataSource()
|
||||||
|
{
|
||||||
|
_addresses = new List<Address>();
|
||||||
|
_endpoints = new List<Endpoint>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IChangeToken ChangeToken { get; } = NullChangeToken.Singleton;
|
||||||
|
|
||||||
|
public IList<Address> Addresses => _addresses;
|
||||||
|
|
||||||
|
public IList<Endpoint> Endpoint { get; } = new List<Endpoint>();
|
||||||
|
|
||||||
|
protected override IReadOnlyList<Address> GetAddesses() => _addresses;
|
||||||
|
|
||||||
|
protected override IReadOnlyList<Endpoint> GetEndpoints() => _endpoints;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue