{"id":1295,"date":"2018-06-26T08:18:08","date_gmt":"2018-06-26T08:18:08","guid":{"rendered":"http:\/\/sezeromer.com\/?p=1295"},"modified":"2023-02-26T23:54:44","modified_gmt":"2023-02-26T20:54:44","slug":"asp-net-core-ile-web-servis-1","status":"publish","type":"post","link":"https:\/\/sezeromer.com\/en\/asp-net-core-ile-web-servis-1\/","title":{"rendered":"Web Service with ASP.Net Core [1]"},"content":{"rendered":"<p>It is not really necessary to mention the importance of the web service. Behind every technology used today is a service. Thanks to these services, all technological devices can communicate. For example, <strong>Instagram&#8217;s<\/strong> web service provides us with both Android devices, <strong>iOS<\/strong> devices, desktop applications and web applications communicating. We can even share stories from the refrigerator by communicating with <strong>Instagram&#8217;s<\/strong> web service.<\/p>\n<p>In addition to this, we will perform <strong>Asp.Net Core 2.0<\/strong> technology, which <strong>Microsoft<\/strong> has recently been working hard on. At the same time we will reinforce what I said in my last article using layered architecture. Click <a href=\"http:\/\/sezeromer.com\/c-katmanli-mimari\/\">here<\/a> to read the story of the layered architecture.<\/p>\n<p>First we open a blank Solution in Visual Studio. Then we need to add a project to this empty project. The first project we&#8217;ll add is the ASP.NET Core Web Application. Here we will be our controllers. The next 2 types of projects we will add will be the same. This is the Class Library. One of these layers is the data layer and the other layer is the business layer.<\/p>\n<p>After we create the layers, we can start with the tables we will create. Every table has to be an ID. We deal with these IDs. We will create a class for this and make other tables inherit this class. I am creating a class called Entity. I also add an ID into this class. To ensure that the IDs are different from each other, I add a string from the Guid class to each ID. I will add a book table to be an example later. This table will have properties such as Name, Year, Author, Type. We set the book class to inherit from the <strong>Entity<\/strong> class.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">public class Entity\r\n    {\r\n        public string ID { get; set; } = Guid.NewGuid().ToString();\r\n    }<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">public class Kitap : Entity\r\n    {\r\n        public string KitapAdi { get; set; }\r\n        public int Bas\u0131mY\u0131l\u0131 { get; set; }\r\n        public string Yazar { get; set; }\r\n        public string Tur { get; set; }\r\n\r\n    }\r\n<\/pre>\n<\/div>\n<p>So my transactions in the data layer are finished for now. We need to load a few packages before moving on to the business layer. You can access these packages by typing EntityFrameworkCore. We will do all of our operations through these packages, such as establishing relationships between the tables, and migrating transactions. The packages I uploaded are like the visuals.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1298\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/06\/paket.png\" sizes=\"(max-width: 1881px) 100vw, 1881px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/06\/paket.png 1881w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/06\/paket-300x139.png 300w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/06\/paket-768x357.png 768w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/06\/paket-1024x476.png 1024w\" alt=\"\" width=\"1881\" height=\"874\" \/><\/p>\n<p>We will add a Context class to the tables we created by opening a class in our business layer. Of course, to indicate that this class is a DBContext, we need to inherit from DBContext and implement 2 functions. After that, we will add tables with dbset.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">public class OrnekDB : DbContext\r\n    {\r\n        public OrnekDB(DbContextOptions&lt;OrnekDB&gt; options) : base(options)\r\n        {\r\n        }\r\n\r\n        protected OrnekDB()\r\n        {\r\n        }\r\n        public DbSet&lt;Kitap&gt; kitapItems { get; set; }\r\n    }<\/pre>\n<\/div>\n<p>For now, things are done in this layer. I will divide it so that it will not be too long.<\/p>","protected":false},"excerpt":{"rendered":"<p>It is not really necessary to mention the importance of the web service. Behind every technology used today is a service. Thanks to these services, all technological devices can communicate. For example, Instagram&#8217;s web service provides us with both Android devices, iOS devices, desktop applications and web applications communicating. We can even share stories from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":495,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[192,1],"tags":[512,516,515,194,493,205,514,250,395,396,513,378],"class_list":["post-1295","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net-core","category-c-ile-ilgili-yazilar","tag-net","tag-2-0","tag-api","tag-asp","tag-c-sharp","tag-core","tag-instagram","tag-migration","tag-service","tag-servis","tag-visul-studio","tag-web"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1295"}],"collection":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/comments?post=1295"}],"version-history":[{"count":6,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1295\/revisions"}],"predecessor-version":[{"id":2598,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1295\/revisions\/2598"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media\/495"}],"wp:attachment":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media?parent=1295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/categories?post=1295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/tags?post=1295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}