/InjectableServices

NuGet package for creating injectable services for DependencyInjection

Primary LanguageC#MIT LicenseMIT

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();