Replace api with controller instead of minimalapi
This commit is contained in:
@@ -9,9 +9,10 @@ namespace Emergence.services.Extensions
|
||||
{
|
||||
public static class ServiceBuilderExtension
|
||||
{
|
||||
public static IServiceCollection AddServices(this IServiceCollection services)
|
||||
public static IServiceCollection AddEmergenceServices(this IServiceCollection services)
|
||||
{
|
||||
services = services.AddTransient<IUserService, UserService>();
|
||||
services = services.AddTransient<ITenantService, TenantService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ using System.Text;
|
||||
|
||||
namespace Emergence.services.Interface
|
||||
{
|
||||
public interface IService<T> where T : class
|
||||
public interface IService<T, I> where T : class
|
||||
{
|
||||
public Task<IList<T>> GetAllAsync();
|
||||
public Task<T> GetByIdAsync(int id);
|
||||
public Task<T> GetByIdAsync(I id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using Emergence.models;
|
||||
|
||||
namespace Emergence.services.Interface
|
||||
{
|
||||
public interface ITenantService : IService<TenantModel, Guid>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using Emergence.models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Emergence.services.Interface
|
||||
{
|
||||
public interface IUserService : IService<UserModel>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Emergence.models;
|
||||
using Emergence.services.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Emergence.services.Services;
|
||||
|
||||
public class TenantService : ITenantService
|
||||
{
|
||||
private List<TenantModel> testList = [
|
||||
new TenantModel {TenantCode = "FJP", CompanyName ="Fred J Potter" },
|
||||
new TenantModel {TenantCode = "JAZZ", CompanyName ="Jazzbond" },
|
||||
new TenantModel {TenantCode = "TDT", CompanyName ="The Digital Tailor" },
|
||||
new TenantModel {TenantCode = "HBAS", CompanyName ="Hicks Building and Asbestos Services" },
|
||||
];
|
||||
|
||||
public async Task<IList<TenantModel>> GetAllAsync()
|
||||
{
|
||||
return testList;
|
||||
}
|
||||
|
||||
public async Task<TenantModel> GetByIdAsync(Guid id)
|
||||
{
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
return testList.FirstOrDefault(f => f.Id == id);
|
||||
#pragma warning restore CS8603 // Possible null reference return.
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Emergence.models;
|
||||
using Emergence.services.Interface;
|
||||
|
||||
namespace Emergence.services.Services;
|
||||
|
||||
public class UserService : IUserService
|
||||
{
|
||||
private List<UserModel> testList = [
|
||||
new UserModel {Id = 1, Username = "chris", Email ="chris@fjp.com.au" },
|
||||
new UserModel {Id = 2, Username = "kim", Email ="kim@fjp.com.au" },
|
||||
new UserModel {Id = 3, Username = "amanda", Email ="amanda@fjp.com.au" },
|
||||
new UserModel {Id = 4, Username = "reception", Email ="reception@fjp.com.au" },
|
||||
];
|
||||
|
||||
public async Task<IList<UserModel>> GetAllAsync()
|
||||
{
|
||||
return testList;
|
||||
}
|
||||
|
||||
public async Task<UserModel> GetByIdAsync(int id)
|
||||
{
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
return testList.FirstOrDefault(f => f.Id == id);
|
||||
#pragma warning restore CS8603 // Possible null reference return.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user