GithubHelp home page GithubHelp logo

jayli02 / tanvirarjel.extensions.microsoft.dependencyinjection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tanvirarjel/tanvirarjel.extensions.microsoft.dependencyinjection

0.0 0.0 0.0 828 KB

This repository contains the generic service registration in ASP.NET Core Dependency Injection Container.

License: MIT License

C# 100.00%

tanvirarjel.extensions.microsoft.dependencyinjection's Introduction

๐Ÿ‘‘ .NET/.NET Core Dynamic Service Registration

This is a NET 5.0 and .NET Core dynamic service registration library which enables you to register all your services into .NET 5.0 and .NET Core Dependency Injection container at once without exposing the service implementation.

โญ Give a star

If you find this library useful to you, please don't forget to encouraging me to do such more stuffs by giving a star (โญ) to this repository. Thank you.

โœˆ๏ธ How do I get started?

First install the lastest version of TanvirArjel.Extensions.Microsoft.DependencyInjection nuget package into your project as follows:

Install-Package TanvirArjel.Extensions.Microsoft.DependencyInjection

Now in your ConfigureServices method of the Startup class:

public static void ConfigureServices(IServiceCollection services)
{
    services.AddServicesOfAllTypes();
}

Moreover, if you want only specific assemblies to be scanned during type scanning:

public static void ConfigureServices(IServiceCollection services)
{
    // Assemblies start with "TanvirArjel.Web", "TanvirArjel.Application" will only be scanned.
    string[] assembliesToBeScanned = new string[] { "TanvirArjel.Web", "TanvirArjel.Application" };
    services.AddServicesOfAllTypes(assembliesToBeScanned);
}

For Blazor WebAssembly App:

builder.Services.AddServicesOfAllTypes(Assembly.GetExecutingAssembly());

๐Ÿ› ๏ธ Usage:

Now mark your services with any of the ScopedServiceAttribute, TransientServiceAttribute and SingletonServiceAttribute attributes as follows:

// Mark with ScopedServiceAttribute if you want to register `IEmployeeService` as scoped service.
[ScopedService]
public interface IEmployeeService
{
    Task CreateEmployeeAsync(Employee employee);
}

internal class EmployeeService : IEmployeeService 
{
    public async Task CreateEmployeeAsync(Employee employee)
    {
       // Implementation here
    };
}

For hosted service:

[HostedService]
public class TestBackgroundService : BackgroundService
{
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        Console.WriteLine("Hosted service called.");
        await Task.CompletedTask.ConfigureAwait(false);
    }
}

๐Ÿž Bug Report

Dont forget to submit an issue if you face. we will try to resolve as soon as possible.

tanvirarjel.extensions.microsoft.dependencyinjection's People

Contributors

tanvirarjel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.