AspNetCore.DynamicInjection 1.0.2

dotnet add package AspNetCore.DynamicInjection --version 1.0.2                
NuGet\Install-Package AspNetCore.DynamicInjection -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspNetCore.DynamicInjection" Version="1.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.DynamicInjection --version 1.0.2                
#r "nuget: AspNetCore.DynamicInjection, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AspNetCore.DynamicInjection as a Cake Addin
#addin nuget:?package=AspNetCore.DynamicInjection&version=1.0.2

// Install AspNetCore.DynamicInjection as a Cake Tool
#tool nuget:?package=AspNetCore.DynamicInjection&version=1.0.2                

Dynamic Dependency Injections Build status NuGet Badge NuGet Badge

Default implementation of dynamic dependency injections in ASP.NET Core project

Namespace

using Microsoft.Extensions.DependencyInjection.DynamicInjection

Code Syntax

  • If your project is single

     public void ConfigureServices(IServiceCollection services)
     {
        services.AddServicesOfType<IScopedService>();
        services.AddServicesAttributeOfType<ScopedServiceAttribute>();      
     }
    
  • If your project is multiple

      public void ConfigureServices(IServiceCollection services)
      {
          //Assemblies start with "Demo.DynamicInjections", "Demo.Repository", "Demo.Manager" will only be scanned.
          string[] assembliesToBeScanned = new string[] { "Demo.DynamicInjections", "Demo.Manager", "Demo.Repository" };
          services.AddServicesOfType<IScopedService>(assembliesToBeScanned);
          services.AddServicesAttributeOfType<ScopedServiceAttribute>(assembliesToBeScanned);
      }
    
  • Every interface can hold attribute- Scoped Service

    [ScopedService]
    public interface IStudentService
    {
        List<Student> GetStudents();
    }
    
  • As usual calling code

    public class StudentController : Controller
    {
        private readonly IStudentService _studentService;
    
        public StudentController(IStudentService studentService)
        {
            _studentService = studentService;
        }
    
        public IActionResult Index()
        {
            var studentsByService = _studentService.GetStudents();
    
            return View();
        }
    }
    
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 453 2/12/2021
1.0.1 352 2/12/2021
1.0.0 366 2/9/2021