Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 722 Bytes

README.md

File metadata and controls

37 lines (27 loc) · 722 Bytes

InjectableServices

  1. Add Injectable attribute to your service

    using InjectableServices;
    
    // The attribute
    [Injectable(ServiceLifetime.Scoped)]
    public class ItemService : IItemService
    {
        private DataContext Context { get; }
    
        public ItemService(DataContext dataContext)
        {
            Context = dataContext;
        }
    
        public Item[] GetAllItems()
        {
            return Context.Items.ToArray();
        }
    }
  2. Easily register injectable services

    using InjectableServices;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // The services registration
    builder.Services.AddInjectableServices();
    
    var app = builder.Build();