From 14ebe20a56327ea97718c9679c93f455ce0eb956 Mon Sep 17 00:00:00 2001 From: Kira Jiroux Date: Mon, 17 Feb 2025 14:02:20 -0500 Subject: [PATCH] Add DependencyInjection for Article/Pokemon Services. --- Portfolio.Application/DependencyInjection.cs | 22 +++++++++ .../Portfolio.Application.csproj | 4 ++ .../Services/Articles/ArticleService.cs | 34 ++++++++++++++ .../Services/Articles/IArticleService.cs | 14 ++++++ .../PokemonService/IPokemonService.cs | 14 ++++++ .../Services/PokemonService/PokemonService.cs | 47 +++++++++++++++++++ .../{ => Features}/Articles/Article.cs | 2 +- Portfolio.Domain/Features/Pokemon/Pokemon.cs | 18 +++++++ Portfolio.Domain/Pokemon/Pokemon.cs | 18 ------- Portfolio.WebUI.Server/Program.cs | 1 + 10 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 Portfolio.Application/DependencyInjection.cs create mode 100644 Portfolio.Application/Services/Articles/ArticleService.cs create mode 100644 Portfolio.Application/Services/Articles/IArticleService.cs create mode 100644 Portfolio.Application/Services/PokemonService/IPokemonService.cs create mode 100644 Portfolio.Application/Services/PokemonService/PokemonService.cs rename Portfolio.Domain/{ => Features}/Articles/Article.cs (90%) create mode 100644 Portfolio.Domain/Features/Pokemon/Pokemon.cs delete mode 100644 Portfolio.Domain/Pokemon/Pokemon.cs diff --git a/Portfolio.Application/DependencyInjection.cs b/Portfolio.Application/DependencyInjection.cs new file mode 100644 index 0000000..c64e9fa --- /dev/null +++ b/Portfolio.Application/DependencyInjection.cs @@ -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(); + services.AddScoped(); + + return services; + } + } +} diff --git a/Portfolio.Application/Portfolio.Application.csproj b/Portfolio.Application/Portfolio.Application.csproj index afb0ea7..f587933 100644 --- a/Portfolio.Application/Portfolio.Application.csproj +++ b/Portfolio.Application/Portfolio.Application.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/Portfolio.Application/Services/Articles/ArticleService.cs b/Portfolio.Application/Services/Articles/ArticleService.cs new file mode 100644 index 0000000..a26bd48 --- /dev/null +++ b/Portfolio.Application/Services/Articles/ArticleService.cs @@ -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
GetAllArticles() + { + return new List
() { + + 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?", + + } + }; + + } + } +} diff --git a/Portfolio.Application/Services/Articles/IArticleService.cs b/Portfolio.Application/Services/Articles/IArticleService.cs new file mode 100644 index 0000000..7bf3f23 --- /dev/null +++ b/Portfolio.Application/Services/Articles/IArticleService.cs @@ -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
GetAllArticles(); + } +} diff --git a/Portfolio.Application/Services/PokemonService/IPokemonService.cs b/Portfolio.Application/Services/PokemonService/IPokemonService.cs new file mode 100644 index 0000000..9480cea --- /dev/null +++ b/Portfolio.Application/Services/PokemonService/IPokemonService.cs @@ -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 GetAllPokemon(); + } +} diff --git a/Portfolio.Application/Services/PokemonService/PokemonService.cs b/Portfolio.Application/Services/PokemonService/PokemonService.cs new file mode 100644 index 0000000..a9a52ea --- /dev/null +++ b/Portfolio.Application/Services/PokemonService/PokemonService.cs @@ -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 GetAllPokemon() + { + return new List() { + + 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" + + }, + }; + } + } +} diff --git a/Portfolio.Domain/Articles/Article.cs b/Portfolio.Domain/Features/Articles/Article.cs similarity index 90% rename from Portfolio.Domain/Articles/Article.cs rename to Portfolio.Domain/Features/Articles/Article.cs index 7cb2a81..8f8cf76 100644 --- a/Portfolio.Domain/Articles/Article.cs +++ b/Portfolio.Domain/Features/Articles/Article.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Portfolio.Domain.Articles +namespace Portfolio.Domain.Features.Articles { public class Article { diff --git a/Portfolio.Domain/Features/Pokemon/Pokemon.cs b/Portfolio.Domain/Features/Pokemon/Pokemon.cs new file mode 100644 index 0000000..ed0ab65 --- /dev/null +++ b/Portfolio.Domain/Features/Pokemon/Pokemon.cs @@ -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; } + + } +} diff --git a/Portfolio.Domain/Pokemon/Pokemon.cs b/Portfolio.Domain/Pokemon/Pokemon.cs deleted file mode 100644 index 2661353..0000000 --- a/Portfolio.Domain/Pokemon/Pokemon.cs +++ /dev/null @@ -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; } - - } -} diff --git a/Portfolio.WebUI.Server/Program.cs b/Portfolio.WebUI.Server/Program.cs index 44b6af2..d837387 100644 --- a/Portfolio.WebUI.Server/Program.cs +++ b/Portfolio.WebUI.Server/Program.cs @@ -5,6 +5,7 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorComponents(); + var app = builder.Build(); // Configure the HTTP request pipeline.