Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
fix(client): 允许没有打任何特性的接口被设置成服务端和客户端
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderJames committed Jan 18, 2018
1 parent 94e7d58 commit 58eaa7a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Shriek.Samples.WebApiProxy.Contracts
{
public interface ITcpTestService
public interface ISimpleInterface
{
Task<string> Test(string sth);
}
Expand Down
11 changes: 5 additions & 6 deletions samples/Shriek.Samples.WebApiProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static void Main(string[] args)
{
opt.AddWebApiProxy<SampleApiProxy>();
opt.AddWebApiProxy<Samples.Services.SampleApiProxy>();
opt.AddService<ISimpleInterface>();
});

//服务里注册代理客户端
Expand All @@ -42,13 +43,14 @@ public static void Main(string[] args)
{
opt.AddWebApiProxy<SampleApiProxy>("http://localhost:8081");
opt.AddWebApiProxy<Samples.Services.SampleApiProxy>("http://localhost:8080");
opt.AddService<ISimpleInterface>("http://localhost:8080");
})
.BuildServiceProvider();

var todoService = provider.GetService<ITodoService>();
var testService = provider.GetService<ITestService>();
var sampleTestService = provider.GetService<Samples.Services.ITestService>();
var tcpService = provider.GetService<ITcpTestService>();
var tcpService = provider.GetService<ISimpleInterface>();

Console.ReadKey();

Expand All @@ -71,11 +73,8 @@ public static void Main(string[] args)
var result3 = sampleTestService.Test("elderjames").Result;
Console.WriteLine(JsonConvert.SerializeObject(result3));

Console.WriteLine("press any key to tcp testing...");
Console.ReadKey();

//var result4 = tcpService.Test("hahaha").Result;
//Console.WriteLine(JsonConvert.SerializeObject(result4));
var result4 = tcpService.Test("hahaha").Result;
Console.WriteLine(JsonConvert.SerializeObject(result4));

Console.ReadKey();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Shriek.Samples.WebApiProxy.Services
{
public class TcpTestService : ITcpTestService
public class SimpleInterface : ISimpleInterface
{
public async Task<string> Test(string sth)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Shriek.ServiceProxy.Http/WebApiProxyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public static IServiceCollection AddWebApiProxy(this IServiceCollection service,

foreach (var type in option.RegisteredServices)
{
if (type.Value.IsInterface && type.Value.GetMethods()
.SelectMany(m => m.GetCustomAttributes(typeof(ApiActionAttribute), true)).Any())
if (type.Value.IsInterface/* && type.Value.GetMethods().SelectMany(m => m.GetCustomAttributes(typeof(ApiActionAttribute), true)).Any()*/)
{
var proxy = ProxyGenerator.CreateInterfaceProxyWithoutTarget(type.Value, new HttpApiClient(type.Key ?? option.ProxyHost));
service.AddSingleton(type.Value, x => proxy);
Expand Down

0 comments on commit 58eaa7a

Please sign in to comment.