Add DependencyInjection for Article/Pokemon Services.
This commit is contained in:
parent
4a2d6dfd87
commit
14ebe20a56
|
@ -0,0 +1,22 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Portfolio.Application.Services.Articles;
|
||||||
|
using Portfolio.Application.Services.PokemonService;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Portfolio.Application
|
||||||
|
{
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddApplication(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddScoped<IArticleService, ArticleService>();
|
||||||
|
services.AddScoped<IPokemonService, PokemonService>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,10 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Portfolio.Domain\Portfolio.Domain.csproj" />
|
<ProjectReference Include="..\Portfolio.Domain\Portfolio.Domain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
using Portfolio.Domain.Features.Articles;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Portfolio.Application.Services.Articles
|
||||||
|
{
|
||||||
|
public class ArticleService : IArticleService
|
||||||
|
{
|
||||||
|
public List<Article> GetAllArticles()
|
||||||
|
{
|
||||||
|
return new List<Article>() {
|
||||||
|
|
||||||
|
new Article
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Title = "Fantasy",
|
||||||
|
Content = "Pink ponies and purple giraffes roamed the field. Cotton candy grew from the ground as a chocolate river meandered off to the side. What looked like stones in the pasture were actually rock candy. Everything in her dream seemed to be perfect except for the fact that she had no mouth.",
|
||||||
|
|
||||||
|
},
|
||||||
|
new Article
|
||||||
|
{
|
||||||
|
Id = 2,
|
||||||
|
Title = "Why",
|
||||||
|
Content = "Sometimes there isn't a good answer. No matter how you try to rationalize the outcome, it doesn't make sense. And instead of an answer, you are simply left with a question. Why?",
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using Portfolio.Domain.Features.Articles;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Portfolio.Application.Services.Articles
|
||||||
|
{
|
||||||
|
public interface IArticleService
|
||||||
|
{
|
||||||
|
List<Article> GetAllArticles();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using Portfolio.Domain.Features.Pokemon;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Portfolio.Application.Services.PokemonService
|
||||||
|
{
|
||||||
|
public interface IPokemonService
|
||||||
|
{
|
||||||
|
List<Pokemon> GetAllPokemon();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
using Portfolio.Domain.Features.Articles;
|
||||||
|
using Portfolio.Domain.Features.Pokemon;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Portfolio.Application.Services.PokemonService
|
||||||
|
{
|
||||||
|
public class PokemonService : IPokemonService
|
||||||
|
{
|
||||||
|
public List<Pokemon> GetAllPokemon()
|
||||||
|
{
|
||||||
|
return new List<Pokemon>() {
|
||||||
|
|
||||||
|
new Pokemon
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
PokemonId = "001",
|
||||||
|
PokemonName = "Bulbasaur",
|
||||||
|
SleepType = "Dozing",
|
||||||
|
Speciality = "Ingredients"
|
||||||
|
|
||||||
|
},
|
||||||
|
new Pokemon
|
||||||
|
{
|
||||||
|
Id = 2,
|
||||||
|
PokemonId = "002",
|
||||||
|
PokemonName = "Ivysaur",
|
||||||
|
SleepType = "Dozing",
|
||||||
|
Speciality = "Ingredients"
|
||||||
|
|
||||||
|
},
|
||||||
|
new Pokemon
|
||||||
|
{
|
||||||
|
Id = 3,
|
||||||
|
PokemonId = "003",
|
||||||
|
PokemonName = "Venasaur",
|
||||||
|
SleepType = "Dozing",
|
||||||
|
Speciality = "Ingredients"
|
||||||
|
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Portfolio.Domain.Articles
|
namespace Portfolio.Domain.Features.Articles
|
||||||
{
|
{
|
||||||
public class Article
|
public class Article
|
||||||
{
|
{
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Portfolio.Domain.Features.Pokemon
|
||||||
|
{
|
||||||
|
public class Pokemon
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string PokemonId { get; set; }
|
||||||
|
public required string PokemonName { get; set; }
|
||||||
|
public required string SleepType { get; set; }
|
||||||
|
public required string Speciality { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,18 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Portfolio.Domain.Pokemon
|
|
||||||
{
|
|
||||||
public class Pokemon
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string PokemonId { get; set; }
|
|
||||||
public string PokemonName { get; set; }
|
|
||||||
public string SleepType { get; set; }
|
|
||||||
public string Speciality { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorComponents();
|
builder.Services.AddRazorComponents();
|
||||||
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|
Loading…
Reference in New Issue