Commit 7766d408 authored by Savorboard's avatar Savorboard

refactor and remove files.

parent 5a00edda
namespace DotNetCore.CAP.Dashboard.GatewayProxy
{
public class HostAndPort
{
public HostAndPort(string downstreamHost, int downstreamPort)
{
DownstreamHost = downstreamHost?.Trim('/');
DownstreamPort = downstreamPort;
}
public string DownstreamHost { get; private set; }
public int DownstreamPort { get; private set; }
}
}
\ No newline at end of file
using System;
using System.Collections.Concurrent;
using Microsoft.AspNetCore.Http;
namespace DotNetCore.CAP.Dashboard.GatewayProxy
{
public class HttpDataRepository : IRequestScopedDataRepository
{
private readonly IHttpContextAccessor _httpContextAccessor;
public HttpDataRepository(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public void Add<T>(string key, T value)
{
_httpContextAccessor.HttpContext.Items.Add(key, value);
}
public T Get<T>(string key)
{
object obj;
if (_httpContextAccessor.HttpContext.Items.TryGetValue(key, out obj))
{
return (T)obj;
}
throw new Exception($"Unable to find data for key: {key}");
}
}
public class ScopedDataRepository : IRequestScopedDataRepository
{
private readonly ConcurrentDictionary<string, object> dictionary = null;
public ScopedDataRepository()
{
dictionary = new ConcurrentDictionary<string, object>();
}
public void Add<T>(string key, T value)
{
dictionary.AddOrUpdate(key, value, (k, v) => value);
}
public T Get<T>(string key)
{
if (dictionary.TryGetValue(key, out object t))
{
return (T)t;
}
throw new Exception($"Unable to find data for key: {key}");
}
}
}
\ No newline at end of file
namespace DotNetCore.CAP.Dashboard.GatewayProxy
{
public interface IRequestScopedDataRepository
{
void Add<T>(string key, T value);
T Get<T>(string key);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment