-
Notifications
You must be signed in to change notification settings - Fork 0
AddressService
Derek Peacock edited this page Dec 21, 2022
·
2 revisions
This service class will have CRUD methods for:-
- GetAllAddresses()
- GetAddress(int id)
- CreateAddress()
- EditAddress(int id)
- ViewAddress(int id)
These can be setyup as an Interface (IAddressService) which defines the methods for the AddressService to implement. This would be more flexible for future enhancements.
using BlazorShoes.Data;
using BlazorShoes.Models;
namespace BlazorShoes.Services
{
public class AddressService
{
private readonly ApplicationDbContext _context;
public AddressService(ApplicationDbContext context)
{
_context = context;
}
public List<Address> GetAddresses()
{
var addressList = _context.Addresses.ToList();
return addressList;
}
}
}The Service must be registered in the program.cs class
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
// Add Services and API Controllers
builder.Services.AddScoped<BasketService>();
builder.Services.AddScoped<AddressService>();
builder.Services.AddScoped<AddressesController>();BNU CO550 Web Applications | Dr Derek Peacock | 2022 Semester 1
Recorded Videos
ASP.NET Core 8
Blazor
React
MS Fabric
Filtering Products
Partial Pages
Git & GitHub
2021 Project Demos
Blazor CRUD
Address Service
API Controller
AddressTable 1
AddressTable 2
Upsert Address
Logbooks
LogBook 1
LogBook 2
LogBook 3
LogBook 4
LogBook 5