Skip to content

Commit 7131a08

Browse files
Add project files.
1 parent 9c09115 commit 7131a08

File tree

11 files changed

+238
-0
lines changed

11 files changed

+238
-0
lines changed

GeeksShop-DI.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32519.111
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeeksShop-DI", "GeeksShop-DI\GeeksShop-DI.csproj", "{89C8D3BA-0C74-478C-9E67-3C6033590C56}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{89C8D3BA-0C74-478C-9E67-3C6033590C56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{89C8D3BA-0C74-478C-9E67-3C6033590C56}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{89C8D3BA-0C74-478C-9E67-3C6033590C56}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{89C8D3BA-0C74-478C-9E67-3C6033590C56}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {FF93607A-FED3-4316-87B3-C0BA885783F7}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using GeeksShop_DI.Models;
2+
using GeeksShop_DI.Services.Interfaces;
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Mvc;
5+
using GeeksShop_DI.Services;
6+
7+
namespace GeeksShop_DI.Controllers
8+
{
9+
[Route("api/[controller]")]
10+
[ApiController]
11+
public class ProductController : ControllerBase
12+
{
13+
IProduct _product;
14+
public ProductController(IProduct product)
15+
{
16+
this._product = product;
17+
}
18+
19+
20+
21+
[HttpGet]
22+
[Route("GetProducts")]
23+
public List<Product> GetProducts()
24+
{
25+
return this._product.GetProducts();
26+
}
27+
}
28+
}

GeeksShop-DI/GeeksShop-DI.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>GeeksShop_DI</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
12+
</ItemGroup>
13+
14+
</Project>

GeeksShop-DI/Models/Product.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace GeeksShop_DI.Models
2+
{
3+
public class Product
4+
{
5+
public int Id { get; set; }
6+
7+
public string Name { get; set; } = string.Empty;
8+
9+
public decimal ListPrice { get; set; }
10+
}
11+
}

GeeksShop-DI/Program.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
using GeeksShop_DI.Services;
3+
using GeeksShop_DI.Services.Interfaces;
4+
5+
var builder = WebApplication.CreateBuilder(args);
6+
7+
// Add services to the container.
8+
9+
builder.Services.AddControllers();
10+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
11+
builder.Services.AddEndpointsApiExplorer();
12+
builder.Services.AddSwaggerGen();
13+
14+
builder.Services.AddScoped<IProduct, PrimeDayProductService>();
15+
var app = builder.Build();
16+
17+
// Configure the HTTP request pipeline.
18+
if (app.Environment.IsDevelopment())
19+
{
20+
app.UseSwagger();
21+
app.UseSwaggerUI();
22+
}
23+
24+
app.UseHttpsRedirection();
25+
26+
app.UseAuthorization();
27+
28+
app.MapControllers();
29+
30+
app.Run();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:55284",
8+
"sslPort": 44383
9+
}
10+
},
11+
"profiles": {
12+
"GeeksShop_DI": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "https://localhost:7252;http://localhost:5252",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"IIS Express": {
23+
"commandName": "IISExpress",
24+
"launchBrowser": true,
25+
"launchUrl": "swagger",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using GeeksShop_DI.Models;
2+
3+
namespace GeeksShop_DI.Services.Interfaces
4+
{
5+
public interface IProduct
6+
{
7+
List<Product> GetProducts();
8+
}
9+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using GeeksShop_DI.Models;
2+
using GeeksShop_DI.Services.Interfaces;
3+
4+
namespace GeeksShop_DI.Services
5+
{
6+
public class PrimeDayProductService : IProduct
7+
{
8+
public List<Product> GetProducts()
9+
{
10+
List<Product> products = new List<Product>()
11+
{
12+
new Product()
13+
{
14+
Id = 4,
15+
Name = "Galaxy A15 Mobile",
16+
ListPrice = 400 - PrimeDayDiscount
17+
},
18+
new Product()
19+
{
20+
Id = 5,
21+
Name = "Laptop",
22+
ListPrice = 500 - PrimeDayDiscount
23+
},
24+
new Product()
25+
{
26+
Id = 3,
27+
Name = "Pen drive",
28+
ListPrice = 300 - PrimeDayDiscount
29+
}
30+
};
31+
return products;
32+
}
33+
34+
public int PrimeDayDiscount
35+
{
36+
get { return 10; }
37+
}
38+
}
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using GeeksShop_DI.Models;
2+
using GeeksShop_DI.Services.Interfaces;
3+
4+
namespace GeeksShop_DI.Services
5+
{
6+
public class ProductService : IProduct
7+
{
8+
public List<Product> GetProducts()
9+
{
10+
List<Product> products = new List<Product>()
11+
{
12+
new Product()
13+
{
14+
Id = 1,
15+
Name = "Galaxy A13 Mobile",
16+
ListPrice = 100
17+
},
18+
new Product()
19+
{
20+
Id = 2,
21+
Name = "Air Pods",
22+
ListPrice = 200
23+
},
24+
new Product()
25+
{
26+
Id = 3,
27+
Name = "Pen drive",
28+
ListPrice = 300
29+
}
30+
};
31+
return products;
32+
}
33+
}
34+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)