namespace BlazorApp.Components.Pages.BlogPage; public class BlogService { private static Lazy _instance = new Lazy(() => new BlogService()); public static BlogService Instance = _instance.Value; private List posts = new List(); private BlogService() { } public void CreatePost(PostItem post) { if(posts.Count > 0) post.Id = posts[^1].Id + 1; else post.Id = 1; posts.Add(post); } public List ReadPosts() { foreach (var post in posts) Console.WriteLine($"READ {post.Id} : {post.Title} = {post.Content}"); return this.posts; } public PostItem ReadPost(int id) { foreach (var post in posts) { if (post.Id == id) return post; } return null; } public void UpdatePost(PostItem post,string title, string content) { post.Title = title; post.Content = content; } public void DeletePost(int id) { PostItem post = ReadPost(id); posts.Remove(post); } }