Browse Source

增加TestApi 修复assemblies

master
Nice 3 years ago
parent
commit
a30c3b20be
  1. 34
      Gear.Test.Api/Controllers/WeatherForecastController.cs
  2. 15
      Gear.Test.Api/Gear.Test.Api.csproj
  3. 26
      Gear.Test.Api/Program.cs
  4. 31
      Gear.Test.Api/Properties/launchSettings.json
  5. 57
      Gear.Test.Api/Startup.cs
  6. 15
      Gear.Test.Api/WeatherForecast.cs
  7. 9
      Gear.Test.Api/appsettings.Development.json
  8. 10
      Gear.Test.Api/appsettings.json
  9. 6
      Gear.sln
  10. 7
      Gear/Gear/Infrastructure/Extensions/ServiceCollectionServiceExtensions.cs

34
Gear.Test.Api/Controllers/WeatherForecastController.cs

@ -0,0 +1,34 @@
using Gear.Abstractions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Gear.Test.Api.Controllers
{
public class WeatherForecastController :AppService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public IEnumerable<WeatherForecast> Get()
{
var d = LazyServiceProvider;
var c = Configuration;
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}

15
Gear.Test.Api/Gear.Test.Api.csproj

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Gear\Gear.csproj" />
</ItemGroup>
</Project>

26
Gear.Test.Api/Program.cs

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Gear.Test.Api
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

31
Gear.Test.Api/Properties/launchSettings.json

@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:44378",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Gear.Test.Api": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

57
Gear.Test.Api/Startup.cs

@ -0,0 +1,57 @@
using Gear.Infrastructure.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Gear.Test.Api
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddGear();
services.AddDynamicWebApi();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Gear.Test.Api", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Gear.Test.Api v1"));
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

15
Gear.Test.Api/WeatherForecast.cs

@ -0,0 +1,15 @@
using System;
namespace Gear.Test.Api
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}

9
Gear.Test.Api/appsettings.Development.json

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

10
Gear.Test.Api/appsettings.json

@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

6
Gear.sln

@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.31605.320
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gear", "Gear\Gear.csproj", "{E98AD43A-28B5-4046-805E-313EF48D9AEE}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gear", "Gear\Gear.csproj", "{E98AD43A-28B5-4046-805E-313EF48D9AEE}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gear.Test.Api", "Gear.Test.Api\Gear.Test.Api.csproj", "{D8E0FF08-B8FA-45AE-B20A-6393B1DBCF18}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{E98AD43A-28B5-4046-805E-313EF48D9AEE}.Debug|Any CPU.Build.0 = Debug|Any CPU {E98AD43A-28B5-4046-805E-313EF48D9AEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E98AD43A-28B5-4046-805E-313EF48D9AEE}.Release|Any CPU.ActiveCfg = Release|Any CPU {E98AD43A-28B5-4046-805E-313EF48D9AEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E98AD43A-28B5-4046-805E-313EF48D9AEE}.Release|Any CPU.Build.0 = Release|Any CPU {E98AD43A-28B5-4046-805E-313EF48D9AEE}.Release|Any CPU.Build.0 = Release|Any CPU
{D8E0FF08-B8FA-45AE-B20A-6393B1DBCF18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8E0FF08-B8FA-45AE-B20A-6393B1DBCF18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8E0FF08-B8FA-45AE-B20A-6393B1DBCF18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8E0FF08-B8FA-45AE-B20A-6393B1DBCF18}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

7
Gear/Gear/Infrastructure/Extensions/ServiceCollectionServiceExtensions.cs

@ -34,7 +34,12 @@ namespace Gear.Infrastructure.Extensions
!lib.Serviceable && !lib.Serviceable &&
lib.Type != "package" && lib.Type != "package" &&
lib.Type != "referenceassembly"). lib.Type != "referenceassembly").
Select(lib => AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(lib.Name))); Select(lib => AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(lib.Name))).ToList();
if (!assemblies.Contains(typeof(ServiceCollectionServiceExtensions).Assembly))
{
assemblies.Add(typeof(ServiceCollectionServiceExtensions).Assembly);
}
foreach (var assembly in assemblies) foreach (var assembly in assemblies)
{ {

Loading…
Cancel
Save