Initial API setup and basic program functioning

This commit is contained in:
2026-03-24 12:29:07 +10:30
parent e5fcaad365
commit f26ff6e04a
17 changed files with 279 additions and 0 deletions
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Emergence.models\Emergence.models.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,19 @@
using Emergence.services.Interface;
using Emergence.services.Services;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
namespace Emergence.services.Extensions
{
public static class ServiceBuilderExtension
{
public static IServiceCollection AddServices(this IServiceCollection services)
{
services = services.AddTransient<IUserService, UserService>();
return services;
}
}
}
+12
View File
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Emergence.services.Interface
{
public interface IService<T> where T : class
{
public Task<IList<T>> GetAllAsync();
public Task<T> GetByIdAsync(int id);
}
}
@@ -0,0 +1,11 @@
using Emergence.models;
using System;
using System.Collections.Generic;
using System.Text;
namespace Emergence.services.Interface
{
public interface IUserService : IService<UserModel>
{
}
}
@@ -0,0 +1,26 @@
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.
}
}