Skip to content

NuGet package for creating injectable services for DependencyInjection

License

Notifications You must be signed in to change notification settings

maxchistt/InjectableServices

Repository files navigation

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