Skip to content

Commit fc6a228

Browse files
committed
Contracts added, common deprecated, enhancement
1 parent 144b738 commit fc6a228

19 files changed

+57
-70
lines changed

src/NetCoreStack.Proxy/DefaultHeaderProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32

43
namespace NetCoreStack.Proxy
54
{

src/NetCoreStack.Proxy/DefaultHttpClientAccessor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Net.Http;
1+
using System.Net.Http;
32

43
namespace NetCoreStack.Proxy
54
{

src/NetCoreStack.Proxy/Extensions/DictionaryExtensions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Globalization;
6-
using System.Net;
76

87
namespace NetCoreStack.Proxy.Extensions
98
{
@@ -25,6 +24,17 @@ private static string TypeParser(KeyValuePair<string, object> selector)
2524
return selector.Value.ToString();
2625
}
2726

27+
public static void Merge(this IDictionary<string, object> instance, IDictionary<string, object> from, bool replaceExisting)
28+
{
29+
foreach (KeyValuePair<string, object> entry in from)
30+
{
31+
if (replaceExisting || !instance.ContainsKey(entry.Key))
32+
{
33+
instance[entry.Key] = entry.Value;
34+
}
35+
}
36+
}
37+
2838
public static void MergeArgs(this IDictionary<string, object> dictionary, object[] args, ParameterDescriptor[] parameters)
2939
{
3040
if (args.Length == 0)

src/NetCoreStack.Proxy/Extensions/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.DependencyInjection;
44
using Microsoft.Extensions.DependencyInjection.Extensions;
5-
using NetCoreStack.Common;
5+
using NetCoreStack.Contracts;
66
using NetCoreStack.Proxy.Internal;
77
using System;
88
using System.Reflection;

src/NetCoreStack.Proxy/Extensions/TypeCoreExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using NetCoreStack.Common;
1+
using NetCoreStack.Contracts;
22
using System;
33
using System.Reflection;
44
using System.Threading.Tasks;
@@ -35,11 +35,11 @@ internal static bool IsGenericTask(this Type type)
3535
return false;
3636
}
3737

38-
internal static bool IsDirectStreamTransport(this Type returnType)
38+
internal static bool IsDirectStreamTransport<TType>(this Type returnType)
3939
{
4040
var result = false;
4141

42-
if (returnType.IsAssignableFrom(typeof(CollectionResult)))
42+
if (returnType.IsAssignableFrom(typeof(CollectionResult<TType>)))
4343
{
4444
result = true;
4545
}

src/NetCoreStack.Proxy/HttpDispatchProxy.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Mvc;
3-
using NetCoreStack.Proxy.Extensions;
43
using NetCoreStack.Proxy.Internal;
54
using System;
65
using System.Net.Http;

src/NetCoreStack.Proxy/Internal/DefaultProxyTypeManager.cs

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
using NetCoreStack.Common;
1+
using Microsoft.AspNetCore.Mvc.Abstractions;
2+
using Microsoft.AspNetCore.Mvc.ModelBinding;
3+
using NetCoreStack.Contracts;
4+
using NetCoreStack.Proxy.Extensions;
5+
using System;
26
using System.Collections.Generic;
3-
using System.Reflection;
47
using System.Linq;
5-
using System;
6-
using NetCoreStack.Proxy.Extensions;
7-
using Microsoft.AspNetCore.Mvc.Routing;
8-
using Microsoft.AspNetCore.Mvc;
98
using System.Net.Http;
10-
using Microsoft.AspNetCore.Mvc.ModelBinding;
11-
using Microsoft.AspNetCore.Mvc.Abstractions;
12-
using NetCoreStack.Common.Extensions;
9+
using System.Reflection;
1310

1411
namespace NetCoreStack.Proxy.Internal
1512
{
@@ -32,16 +29,16 @@ private IList<ProxyDescriptor> GetProxyDescriptors()
3229
var descriptors = new List<ProxyDescriptor>();
3330
foreach (var proxyType in types)
3431
{
35-
var path = proxyType.GetTypeInfo().GetCustomAttribute<ApiRouteAttribute>();
36-
if (path == null)
32+
var pathAttr = proxyType.GetTypeInfo().GetCustomAttribute<ApiRouteAttribute>();
33+
if (pathAttr == null)
3734
throw new ArgumentNullException($"{nameof(ApiRouteAttribute)} required for Proxy - Api interface.");
3835

39-
if (!path.RegionKey.HasValue())
40-
throw new ArgumentOutOfRangeException($"Specify the \"{nameof(path.RegionKey)}\"!");
36+
if (!pathAttr.RegionKey.HasValue())
37+
throw new ArgumentOutOfRangeException($"Specify the \"{nameof(pathAttr.RegionKey)}\"!");
4138

42-
var route = proxyType.Name.GetApiRawName(path.Template);
39+
var route = proxyType.Name.GetApiRawName(pathAttr.RouteTemplate);
4340

44-
ProxyDescriptor descriptor = new ProxyDescriptor(proxyType, path.RegionKey, route);
41+
ProxyDescriptor descriptor = new ProxyDescriptor(proxyType, pathAttr.RegionKey, route);
4542

4643
var interfaces = proxyType.GetInterfaces()
4744
.Except(new List<Type> { typeof(IApiContract), typeof(IDependency) }).ToList();
@@ -69,21 +66,12 @@ private IList<ProxyDescriptor> GetProxyDescriptors()
6966
proxyMethodDescriptor.Timeout = timeoutAttr.Timeout;
7067

7168
var httpMethodAttribute = method.GetCustomAttributes(inherit: true)
72-
.OfType<HttpMethodAttribute>().FirstOrDefault();
69+
.OfType<HttpMethodMarkerAttribute>().FirstOrDefault();
7370

7471
if (httpMethodAttribute != null)
7572
{
76-
if (httpMethodAttribute is HttpPostAttribute)
73+
if (httpMethodAttribute is HttpPostMarkerAttribute)
7774
proxyMethodDescriptor.HttpMethod = HttpMethod.Post;
78-
79-
else if (httpMethodAttribute is HttpGetAttribute)
80-
proxyMethodDescriptor.HttpMethod = HttpMethod.Get;
81-
82-
else if (httpMethodAttribute is HttpPutAttribute)
83-
proxyMethodDescriptor.HttpMethod = HttpMethod.Put;
84-
85-
else if (httpMethodAttribute is HttpDeleteAttribute)
86-
proxyMethodDescriptor.HttpMethod = HttpMethod.Delete;
8775
}
8876
else
8977
{
@@ -94,18 +82,6 @@ private IList<ProxyDescriptor> GetProxyDescriptors()
9482
proxyMethodDescriptor.Parameters = new List<ParameterDescriptor>();
9583
foreach (var parameter in method.GetParameters())
9684
{
97-
//if (proxyMethodDescriptor.HttpMethod == HttpMethod.Get)
98-
//{
99-
// if (parameter.ParameterType.IsReferenceType() &&
100-
// !typeof(IQueryStringTransferable).IsAssignableFrom(parameter.ParameterType))
101-
// {
102-
// throw new InvalidOperationException($"API methods that take a reference type parameter and are marked with HttpGet " +
103-
// $"should be derived from the {nameof(IQueryStringTransferable)} " +
104-
// $"or method should be marked as HttpPost. MethodName: \"{method.Name}\", " +
105-
// $"ParameterType: \"{parameter.ParameterType.Name}\"");
106-
// }
107-
//}
108-
10985
proxyMethodDescriptor.Parameters.Add(new ParameterDescriptor()
11086
{
11187
Name = parameter.Name,

src/NetCoreStack.Proxy/Internal/ProxyHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.Extensions.DependencyInjection;
3-
using NetCoreStack.Common;
3+
using NetCoreStack.Contracts;
44
using NetCoreStack.Proxy.Extensions;
55
using System;
66
using System.Reflection;

src/NetCoreStack.Proxy/Internal/ProxyResultExecutor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using NetCoreStack.Proxy.Extensions;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
32
using System;
43
using System.Net.Http;
54
using System.Threading.Tasks;

src/NetCoreStack.Proxy/NetCoreStack.Proxy.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.1" />
15+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
1516
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.1" />
1617
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
17-
<PackageReference Include="NetCoreStack.Common" Version="1.0.0-*" />
18+
<PackageReference Include="NetCoreStack.Contracts" Version="1.0.0-preview-173" />
1819
<PackageReference Include="NetCoreStack.DispatchProxyAsync" Version="1.1.0" />
1920
</ItemGroup>
2021

@@ -26,5 +27,5 @@
2627
<Reference Include="System" />
2728
<Reference Include="Microsoft.CSharp" />
2829
</ItemGroup>
29-
30+
3031
</Project>

0 commit comments

Comments
 (0)