{"id":200619,"date":"2020-11-19T02:26:49","date_gmt":"2020-11-18T18:26:49","guid":{"rendered":"http:\/\/4563.org\/?p=200619"},"modified":"2020-11-19T02:26:49","modified_gmt":"2020-11-18T18:26:49","slug":"dotnet-coremongodb-%e5%bc%80%e5%8f%91-web-api","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=200619","title":{"rendered":"dotnet core+mongodb \u5f00\u53d1 web api"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  dotnet core+mongodb \u5f00\u53d1 web api               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zxCoder <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6839\u636e\u5b98\u7f51\u8fd9\u4e2a\u6559\u7a0b https:\/\/docs.microsoft.com\/zh-cn\/aspnet\/core\/tutorials\/first-mongo-app<\/p>\n<p>\u7ed3\u679c\u5728\u914d\u7f6e\u6570\u636e\u5e93\u90e8\u5206\u51fa\u9519\u4e86<\/p>\n<p>\u6559\u7a0b\u7684\u4ee3\u7801\uff1a<\/p>\n<pre><code>public void ConfigureServices(IServiceCollection services) {     \/\/ requires using Microsoft.Extensions.Options     services.Configure&lt;BookstoreDatabaseSettings&gt;(         Configuration.GetSection(nameof(BookstoreDatabaseSettings)));      services.AddSingleton&lt;IBookstoreDatabaseSettings&gt;(sp =&gt;         sp.GetRequiredService&lt;IOptions&lt;BookstoreDatabaseSettings&gt;&gt;().Value);      services.AddControllers(); } <\/code><\/pre>\n<p>\u672c\u5730\u5728 Configuration.GetSection()\u62a5\u9519\uff0cCannot access non-static method &#8216;GetSection&#8217; in static context<\/p>\n<p>\u7f51\u4e0a\u6ca1\u627e\u5230\u540c\u6837\u7684\u9519\u8bef\uff0c\u662f\u6211\u54ea\u4e00\u6b65\u505a\u9519\u4e86\u5417<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4290201\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hotsymbol <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4ece \u7528 .Net core \u8fd9\u4e00\u6b65\u8d77\uff0c\u5c31\u9519\u4e86\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u7528 Java \u5462 \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4290202\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : beginor <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Configuration \u5e94\u8be5\u662f Startup \u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff0c \u770b\u662f\u4e0d\u662f\u6f0f\u4e86\u3002 \u5982\u679c\u4f60\u662f\u7528\u9ed8\u8ba4\u7684\u9879\u76ee\u6a21\u677f\u7684\u8bdd\uff0c\u5e94\u8be5\u662f\u6709\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4290203\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dswyzx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             startup \u6784\u9020\u51fd\u6570\u91cc\u7684 IConfiguration configuration \u53c2\u6570\u5176\u5b9e\u5c31\u662f\u8d4b\u503c\u7ed9\u8fd9\u4e2a Configuration\uff0c\u5176\u6765\u6e90\u5728 Program.cs \u6587\u4ef6\u5939\u5185\u5c06\u4ee5 AddJsonFile \uff08\uff09\u5c06 appsettings.json \u6216\u5176\u4ed6\u6587\u4ef6\u8bfb\u5165\u3002\u53e6\u770b\u4e0b\u4f60\u7684\u9879\u76ee\u91cc json \u914d\u7f6e\u6587\u4ef6\u5c5e\u6027\u662f\u5426\u8bbe\u7f6e\u4e86\u590d\u5236\uff0c\u68c0\u67e5\u751f\u6210\u7684 debug \u8fd0\u884c\u6587\u4ef6\u5939\u4e0b\u662f\u5426\u6709\u914d\u7f6e\u6587\u4ef6\u4e86<br \/>\u53c2\u8003\uff1a https:\/\/docs.microsoft.com\/zh-cn\/aspnet\/core\/fundamentals\/host\/web-host?view=aspnetcore-5.0#set-up-a-host                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4290204\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : OysterQAQ <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 java \u5427\uff0cspring boot + spring data \u81ea\u52a8\u914d\u7f6e\u65e0\u8111\u4e00\u628a\u68ad                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4290205\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : forgottencoast <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @hotsymbol <br \/>@OysterQAQ <br \/>\u56e0\u4e3a\u6709\u4e2a\u91d1\u4e3b\u7ed9\u4e3b 100 \u4e07\u8ba9\u4ed6\u7528 dotnet core+mongodb \u5f00\u53d1 web api \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4290206\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : zxCoder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @forgottencoast \u9634\u9633\u602a\u6c14                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4290207\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : forgottencoast <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zxCoder \u5403\u9971\u4e86\u6491\u7740\u6ca1\u4e8b\u5e72                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4290208\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Bazingal <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u4e0d\u51fa\u4f60\u7684 Configuration \u54ea\u6765\u7684\uff0c\u6b63\u5e38\u5e94\u8be5\u662f\u5728 Startup \u6784\u9020\u65b9\u6cd5\u91cc\u9762\u6ce8\u5165\u7684\uff0c\u4f60\u770b\u4e0b\u662f\u4e0d\u662f<br \/>&#8220;` c#<br \/>public IConfiguration Configuration { get; }<br \/>public Startup(IConfiguration configuration)<br \/>{<br \/> Configuration = configuration;<br \/>}<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>dotnet core+mongo&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200619"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200619"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200619\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200619"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}