Skip to content

Commit 45cd7f5

Browse files
committed
support method returntype and parmater type independent assembly #172
1 parent 7f511b2 commit 45cd7f5

7 files changed

Lines changed: 53 additions & 14 deletions

File tree

src/Surging.Core/Surging.Core.CPlatform/ContainerBuilderExtensions.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,17 @@ public static List<Type> GetInterfaceService(this IServiceBuilder builder)
599599
public static IEnumerable<string> GetDataContractName(this IServiceBuilder builder)
600600
{
601601
var namespaces = new List<string>();
602-
var referenceAssemblies = builder.GetInterfaceService();
603-
referenceAssemblies.ForEach(p =>
602+
var assemblies = builder.GetInterfaceService()
603+
.Select(p=>p.Assembly)
604+
.Union(GetSystemModules())
605+
.Distinct()
606+
.ToList();
607+
608+
assemblies.ForEach(assembly =>
604609
{
605-
namespaces.AddRange(p.Assembly.GetTypes().Where(t => t.GetCustomAttribute<DataContractAttribute>() != null).Select(n => n.Namespace));
610+
namespaces.AddRange(assembly.GetTypes().Where(t => t.GetCustomAttribute<DataContractAttribute>() != null).Select(n => n.Namespace));
606611
});
607-
return namespaces.Distinct();
612+
return namespaces;
608613
}
609614

610615
private static IDictionary<string, string> ConvertDictionary(List<ModulePackage> list)
@@ -645,7 +650,22 @@ private static List<Assembly> GetReferenceAssembly(params string[] virtualPaths)
645650
}
646651
return result;
647652
}
648-
653+
654+
private static List<Assembly> GetSystemModules()
655+
{
656+
var assemblies = new List<Assembly>();
657+
var referenceAssemblies = GetReferenceAssembly();
658+
foreach (var referenceAssembly in referenceAssemblies)
659+
{
660+
var abstractModules = GetAbstractModules(referenceAssembly);
661+
if(abstractModules.Any(p =>p.GetType().IsSubclassOf(typeof(SystemModule))))
662+
{
663+
assemblies.Add(referenceAssembly);
664+
}
665+
}
666+
return assemblies;
667+
}
668+
649669
private static List<AbstractModule> GetAbstractModules(Assembly assembly)
650670
{
651671
var abstractModules = new List<AbstractModule>();

src/Surging.IModuleServices/Surging.IModuleServices.Common/Models/ApiResult.cs renamed to src/Surging.Core/Surging.Core.Common/ApiResult.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-

2-
1+
using System;
2+
using System.Collections.Generic;
33
using System.Runtime.Serialization;
4+
using System.Text;
45

5-
namespace Surging.IModuleServices.Common.Models
6+
namespace Surging.Core.Common
67
{
78
[DataContract]
89
public class ApiResult<T>
910
{
11+
1012
[DataMember]
1113
public int StatusCode { get; set; }
1214

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Surging.Core.CPlatform.Module;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Surging.Core.Common
7+
{
8+
public class CommonModule:SystemModule
9+
{
10+
}
11+
}

src/Surging.Core/Surging.Core.Common/Surging.Core.Common.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<PackageReference Include="Autofac" Version="4.8.1" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\Surging.Core.CPlatform\Surging.Core.CPlatform.csproj" />
13+
</ItemGroup>
14+
715
</Project>

src/Surging.IModuleServices/Surging.IModuleServices.Common/IUserService.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
using Newtonsoft.Json.Linq;
2-
using Surging.Core.Caching;
3-
using Surging.Core.CPlatform;
1+
using Surging.Core.Caching;
2+
using Surging.Core.Common;
43
using Surging.Core.CPlatform.EventBus.Events;
54
using Surging.Core.CPlatform.Filters.Implementation;
65
using Surging.Core.CPlatform.Ioc;
7-
using Surging.Core.CPlatform.Routing.Implementation;
86
using Surging.Core.CPlatform.Runtime.Client.Address.Resolvers.Implementation.Selectors.Implementation;
97
using Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Attributes;
108
using Surging.Core.CPlatform.Support;
119
using Surging.Core.CPlatform.Support.Attributes;
1210
using Surging.Core.KestrelHttpServer;
1311
using Surging.Core.KestrelHttpServer.Internal;
14-
using Surging.Core.ProxyGenerator.Implementation;
1512
using Surging.Core.System.Intercept;
1613
using Surging.IModuleServices.Common.Models;
1714
using System;
1815
using System.Collections.Generic;
19-
using System.Text;
2016
using System.Threading.Tasks;
2117

2218
namespace Surging.IModuleServices.Common

src/Surging.Modules/Surging.Modules.Common/Domain/PersonService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Surging.Core.KestrelHttpServer.Internal;
1414
using System.IO;
1515
using Surging.Core.KestrelHttpServer;
16+
using Surging.Core.Common;
1617

1718
namespace Surging.Modules.Common.Domain
1819
{

src/Surging.Modules/Surging.Modules.Common/Domain/UserService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
using Surging.Core.Common;
23
using Surging.Core.CPlatform.EventBus.Events;
34
using Surging.Core.CPlatform.EventBus.Implementation;
45
using Surging.Core.CPlatform.Ioc;

0 commit comments

Comments
 (0)