Newcats.DependencyInjection 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Newcats.DependencyInjection --version 1.0.2                
NuGet\Install-Package Newcats.DependencyInjection -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="Newcats.DependencyInjection" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Newcats.DependencyInjection --version 1.0.2                
#r "nuget: Newcats.DependencyInjection, 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 Newcats.DependencyInjection as a Cake Addin
#addin nuget:?package=Newcats.DependencyInjection&version=1.0.2

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

依赖注入使用说明

  • 1.在项目的Startup.cs类中,添加依赖注入服务
   public void ConfigureServices(IServiceCollection services)
   {
       services.AddHttpContextAccessor();

       //依赖注入
       services.AddScoped(typeof(DataAccess.IRepository<,>), typeof(DataAccess.SqlServer.Repository<,>));//注册泛型仓储
       services.AddDependencyInjection();//注册依赖
   }
  • 2.对于需要使用依赖注入的接口,手动继承IScopedDependency/ISingletonDependency/ITransientDependency
   public interface IUserInfoService : IScopedDependency
   {
   }
  • 3.具体需要哪个标记接口,看需求,一般Web项目用IScopedDependency
  • 4.程序启动时会扫描bin目录下的所有自己项目的dll文件,然后注册依赖关系
  • 5.对于不会自动生成在bin下的项目dll,请直接引用
  • 6.使用构造函数注入
  • 7.对于不能使用构造函数注入的,可以使用HttpContext.RequestServices.GetService<IService>();
IWorkContext _workContext = context.HttpContext.RequestServices.GetService<IWorkContext>();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Newcats.DependencyInjection:

Package Downloads
Newcats.AspNetCore

Some common modules to make AspNetCore easy.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 1,274 12/1/2021
1.0.2 355 11/18/2021
1.0.1 347 10/20/2021
1.0.0 315 9/2/2021