diff --git "a/\347\216\213\347\216\260\350\276\211/.gitignore" "b/\347\216\213\347\216\260\350\276\211/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..3e8a1553fcff7845c779d3cb8014e151a9931506 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/.gitignore" @@ -0,0 +1,341 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ +# ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true +**/wwwroot/lib/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json.sln" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json.sln" new file mode 100644 index 0000000000000000000000000000000000000000..aa29a5433012d41a682756a3807c63b699a9bdb4 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json.sln" @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30104.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI——DI_json", "WebAPI——DI_json\WebAPI——DI_json.csproj", "{3F2EE9BF-DB7D-4971-B275-4EC695A43D1E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3F2EE9BF-DB7D-4971-B275-4EC695A43D1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F2EE9BF-DB7D-4971-B275-4EC695A43D1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F2EE9BF-DB7D-4971-B275-4EC695A43D1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F2EE9BF-DB7D-4971-B275-4EC695A43D1E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {75652070-527C-4CCC-8A17-C3394AF6DCB5} + EndGlobalSection +EndGlobal diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Controllers/TestController.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Controllers/TestController.cs" new file mode 100644 index 0000000000000000000000000000000000000000..bfc12e06da4d56d7e4294ba4d2fc3879847841fb --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Controllers/TestController.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Diagnostics; +using WebAPI__DI_json.DoMain.Entity; +using WebAPI__DI_json.Helper; +using WebAPI__DI_json.Interface; + +namespace WebAPI__DI_json.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class TestController : ControllerBase + { + private readonly IRespository _UserResitory; + + public TestController(IRespository respository) + { + _UserResitory = respository; + } + + public string Get() + { + var list = _UserResitory.Table.ToList(); + return JsonHelper.JsonSerializeSetting(list); + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Controllers/WeatherForecastController.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Controllers/WeatherForecastController.cs" new file mode 100644 index 0000000000000000000000000000000000000000..0add901d8d649eee0d5e34f0a43bd83e62faf46c --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Controllers/WeatherForecastController.cs" @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using WebAPI__DI_json.DoMain; +using WebAPI__DI_json.Helper; + +namespace WebAPI__DI_json.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private readonly AdminDbContext _db; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger, AdminDbContext dbContext) + { + _logger = logger; + _db = dbContext; + } + + [HttpGet] + public string Get() + { + var list = _db.Users.Include(x => x.Role).ToList(); + + return JsonHelper.JsonSerializeSetting(list); + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/AdminDbContext.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/AdminDbContext.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7b3c03840564a1057ed3a17ec871a10b7cfe464e --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/AdminDbContext.cs" @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Threading.Tasks; +using WebAPI__DI_json.DoMain.Entity; + +namespace WebAPI__DI_json.DoMain +{ + public class AdminDbContext:DbContext + { + public AdminDbContext() + { + + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlServer("Server=N8QU1VYXG0M3H5J;Database=Admin;uid=sa;pwd=123456"); + } + + public DbSet Users { get; set; } + + public DbSet Roles { get; set; } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/BaseEntity.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/BaseEntity.cs" new file mode 100644 index 0000000000000000000000000000000000000000..f22aa6d1f6f12f1e6aae70ffe921ba20556ede19 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/BaseEntity.cs" @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI__DI_json.DoMain +{ + public class BaseEntity + { + public BaseEntity() + { + IsActived = true; + IsDeleted = false; + CreateTime = DateTime.Now; + UpdateTime = DateTime.Now; + } + + public int Id { get; set; } + + public bool IsActived { get; set; } + + public bool IsDeleted { get; set; } + + public DateTime CreateTime { get; set; } + + public DateTime UpdateTime { get; set; } + + public string ReMarks { get; set; } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/DbInitializer.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/DbInitializer.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9ccec366fbde0c12c565b82a0760bba0e2e437c4 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/DbInitializer.cs" @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices.ComTypes; +using System.Threading.Tasks; +using WebAPI__DI_json.DoMain.Entity; + +namespace WebAPI__DI_json.DoMain +{ + public class DbInitializer + { + public static void Seed() + { + var db = new AdminDbContext(); + using (db) + { + db.Database.EnsureCreated(); + + var HasUser = db.Users.Any(); + if (!HasUser) + { + var role = new Role + { + RoleName = "管理员", + Description = "此处省略一百字" + }; + + db.Roles.Add(role); + db.SaveChanges(); + + db.Users.AddRange(new User[] + { + new User + { + UserName ="Admin", + PassWord="123456", + RoleId = role.Id + } + , + new User + { + UserName ="User01", + PassWord="654321", + RoleId = role.Id + } + }); + + db.SaveChanges(); + + + } + + + } + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/Entity/Role.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/Entity/Role.cs" new file mode 100644 index 0000000000000000000000000000000000000000..c4f85522bc9e288d53e89d83f3df219123dd36f2 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/Entity/Role.cs" @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI__DI_json.DoMain.Entity +{ + public class Role:BaseEntity + { + public string RoleName { get; set; } + + public string Description { get; set; } + + public IEnumerable Users { get; set; } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/Entity/User.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/Entity/User.cs" new file mode 100644 index 0000000000000000000000000000000000000000..616df0a7f3721ea7f7e64ad78b9d455811557f6c --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/DoMain/Entity/User.cs" @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI__DI_json.DoMain.Entity +{ + public class User:BaseEntity + { + public string UserName { get; set; } + + public string PassWord { get; set; } + + public int RoleId { get; set; } + + public Role Role { get; set; } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Helper/JsonHelper.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Helper/JsonHelper.cs" new file mode 100644 index 0000000000000000000000000000000000000000..c71ac776abbccdfd637aaebbf14066ddc62f07dc --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Helper/JsonHelper.cs" @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI__DI_json.Helper +{ + public class JsonHelper + { + public static string JsonSerializeSetting(object obj) + { + return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + ContractResolver = new DefaultContractResolver(), + DateFormatString = "yyyy-MM-dd HH:mm:ss" + }); + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Implementation/EfRespository.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Implementation/EfRespository.cs" new file mode 100644 index 0000000000000000000000000000000000000000..f6dc5cd24b2a603b3ee4e597fb61e0944f9fbb91 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Implementation/EfRespository.cs" @@ -0,0 +1,87 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using WebAPI__DI_json.DoMain; +using WebAPI__DI_json.Interface; + +namespace WebAPI__DI_json.Implementation +{ + public class EfRespository : IRespository where T : BaseEntity + { + private readonly AdminDbContext db; + + public EfRespository(AdminDbContext dbContext) + { + db = dbContext; + } + + public DbSet _entity; + + public IQueryable Entity + { + get + { + if (_entity == null) + { + _entity = db.Set(); + } + return _entity; + } + + } + + //查 + public IQueryable Table + { + get + { + return Entity; + } + } + + public T GetById(int Id) + { + return _entity.Where(x => x.Id == Id).FirstOrDefault(); + + } + + //删 + public void Delete(T Entity) + { + this._entity.Remove(Entity); + + db.SaveChanges(); + } + + public void Delete(int Id) + { + var Del = Entity.Where(x => x.Id == Id).FirstOrDefault(); + Delete(Del); + } + + //增 + public void Insert(T Entity) + { + _entity.Add(Entity); + + db.SaveChanges(); + } + + + public void InsertBulk(IEnumerable list) + { + _entity.AddRange(list); + db.SaveChanges(); + } + + //改 + public void Update(T Entity) + { + _entity.Update(Entity); + db.SaveChanges(); + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Interface/IRespository.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Interface/IRespository.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b53d50ef499baa24ae8053c452a49ad3a494687b --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Interface/IRespository.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI__DI_json.Interface +{ + public interface IRespository + { + T GetById(int Id); + + IQueryable Table { get; } + + void Insert(T Entity); + + void InsertBulk(IEnumerable list); + + void Update(T Entity); + + void Delete(T Entity); + + void Delete(int Id); + + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Program.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..d0b010dfb3fe24a28abf650f543963dc24d9ab36 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Program.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace WebAPI__DI_json +{ + 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(); + }); + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Properties/launchSettings.json" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Properties/launchSettings.json" new file mode 100644 index 0000000000000000000000000000000000000000..04d6622aff38d95874bd4836b6177e4d1c4cb69c --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:60964", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "WebAPI__DI_json": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Startup.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Startup.cs" new file mode 100644 index 0000000000000000000000000000000000000000..61f5072830528f1571a7c4f25f7a0ff711ce3dc6 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/Startup.cs" @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +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 WebAPI__DI_json.DoMain; +using WebAPI__DI_json.Implementation; +using WebAPI__DI_json.Interface; + +namespace WebAPI__DI_json +{ + 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.AddDbContext(); + services.AddScoped(typeof(IRespository<>), typeof(EfRespository<>)); + services.AddControllers(); + } + + // 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.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + + DbInitializer.Seed(); + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/WeatherForecast.cs" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/WeatherForecast.cs" new file mode 100644 index 0000000000000000000000000000000000000000..77ea573d518a9b5ba3860146dcdf9a7db7a8a3a2 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/WeatherForecast.cs" @@ -0,0 +1,15 @@ +using System; + +namespace WebAPI__DI_json +{ + 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; } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/WebAPI\342\200\224\342\200\224DI_json.csproj" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/WebAPI\342\200\224\342\200\224DI_json.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..b3427b90d9eed627990fd1e32b3d46a340c44595 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/WebAPI\342\200\224\342\200\224DI_json.csproj" @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + WebAPI__DI_json + + + + + + + + + + diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/appsettings.Development.json" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/appsettings.Development.json" new file mode 100644 index 0000000000000000000000000000000000000000..8983e0fc1c5e2795ccfde0c771c6d66c88ef4a42 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git "a/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/appsettings.json" "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/appsettings.json" new file mode 100644 index 0000000000000000000000000000000000000000..d9d9a9bff6fd6f3ee7ea00de958f135a4a28c6e6 --- /dev/null +++ "b/\347\216\213\347\216\260\350\276\211/WebAPI\342\200\224\342\200\224DI_json/appsettings.json" @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}