An unhandled exception occurred while processing the request

У меня выскочила ошибка: InvalidOperationException: Unable to resolve service for type 'WebApplication4.InteraFaces.IAllClothes' while attempting to activate 'WebApplication4.Controllers.ClothesController'. Startup.cs

using WebApplication4.Data.Mocks;
using WebApplication4.InteraFaces;

namespace WebApplication4
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<IAllClothes, MockClothes>();
            services.AddTransient<IClothesCategory, MockCategory>();
            services.AddMvc();
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStaticFiles();
            app.UseStatusCodePages();   
        }
    }
}

IAllClothes.cs

using WebApplication4.Models;

namespace WebApplication4.InteraFaces
{
    public interface IAllClothes
    {
        IEnumerable<Clothes> Clothe { get; }
        IEnumerable<Clothes>? getFavClothe { get; set; }
         Clothes getObjectClothes(int clothesId);
    }
}

IClothesCategory.cs

using WebApplication4.Models;

namespace WebApplication4.InteraFaces
{
    public interface IClothesCategory
    {
        IEnumerable<Category> AllCategories { get; }
    }
}

ClothesController.cs

using Microsoft.AspNetCore.Mvc;
using WebApplication4.Models;
using WebApplication4.InteraFaces;

namespace WebApplication4.Controllers
{
     public class ClothesController : Controller
     {
         private readonly IAllClothes? _allCLothes;
         private readonly IClothesCategory? _allCategories;

     public ClothesController(IAllClothes iAllCLothes, IClothesCategory? iClothesCat)
     {
         _allCLothes = iAllCLothes;
         _allCategories = iClothesCat;
     }
     public ViewResult List()
     {
         var clothe = _allCLothes?.Clothe;
         return View();
     }
 }

}

MockClothes.cs

using WebApplication4.InteraFaces;
using WebApplication4.Models;

namespace WebApplication4.Data.Mocks
{
public class MockClothes : IAllClothes
{
    private readonly IClothesCategory _categoryclothes = new MockCategory();

    public IEnumerable<Clothes> Clothe
    {
        get
        {
            return new List<Clothes>
            {
                new Clothes { Name = "Stussy Born Raised",
                    shortDesc = "Размеры: S, M, L, XL",
                    longDesc = "Очень крутая и комфортная, все девочки ваши",
                    img = "https://photo.yupoo.com/hunter0824/d2b895e1/920e665f.jpeg",
                    price = 2800,
                    isFavorite = true,
                    available = false,
                    Category = _categoryclothes.AllCategories.First()
                },
                new Clothes { Name = "Supreme Box Logo",
                    shortDesc = "Размеры: S, M, L, XL",
                    longDesc = "Очень крутая и комфортная, все девочки ваши",
                    img = "https://photo.yupoo.com/hunter0824/85fc896b/ded44c51.jpg",
                    price = 2700,
                    isFavorite = false,
                    available = true,
                    Category = _categoryclothes.AllCategories.Last()
                },
                new Clothes { Name = "Polar Big Boy New Logo",
                    shortDesc = "Размеры: S, M, L, XL",
                    longDesc = "Очень крутая и комфортная, все девочки ваши",
                    img = "https://polarskateco.com/cdn/shop/files/Polar-Skate-Co-SP24-Big-Boy-Jeans-Light-Blue-1_672x672.png?v=1708348108",
                    price = 2600,
                    isFavorite = false,
                    available = false,
                    Category = _categoryclothes.AllCategories.Last()
                },
                        new Clothes { Name = "Gallery Dept Basic Tee",
                        shortDesc = "Размеры: S, M, L, XL",
                        longDesc = "Очень крутая и комфортная, все девочки ваши",
                        img = 
       "https://gallerydept.com/cdn/shop/products/whitessfront_720x.jpg?v=1640097298",
                        price = 1400,
                        isFavorite = true,
                        available = true,
                        Category = _categoryclothes.AllCategories.Last()
                    },
                };
            }
        }
        public IEnumerable<Clothes>? getFavClothe { get; set; }

        public Clothes getObjectClothes(int clothesId)
        {
            throw new NotImplementedException();
        }
    }
}

MockCategory.cs

using WebApplication4.InteraFaces;
using WebApplication4.Models;

namespace WebApplication4.Data.Mocks
{
public class MockCategory : IClothesCategory
{
    public IEnumerable<Category> AllCategories
    {
        get
        {
            return new List<Category>
            {
                new Category { categoryName = "Stussy", desc = "New clothes of supreme" },
                new Category { categoryName = "Supreme", desc = "New clothes of supreme" },
                new Category { categoryName = "Polar", desc = "New clothes of polar" },
                new Category { categoryName = "Gallery Dept.", desc = "New colections of gellery dept" }
            };
        }
    }
}

}


Ответы (0 шт):