MicrosoftDI.AddXRefactoring
0.5.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MicrosoftDI.AddXRefactoring --version 0.5.0
NuGet\Install-Package MicrosoftDI.AddXRefactoring -Version 0.5.0
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="MicrosoftDI.AddXRefactoring" Version="0.5.0"> <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 MicrosoftDI.AddXRefactoring --version 0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MicrosoftDI.AddXRefactoring, 0.5.0"
#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 MicrosoftDI.AddXRefactoring as a Cake Addin #addin nuget:?package=MicrosoftDI.AddXRefactoring&version=0.5.0 // Install MicrosoftDI.AddXRefactoring as a Cake Tool #tool nuget:?package=MicrosoftDI.AddXRefactoring&version=0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Microsoft DI AddX Refactoring Provider
This project provides Roslyn code refactoring, which automatically adds Add(Singleton|Scoped|Transient) from your new class declaration into nearest DI registration point. It could be default ConfigureServices in Startup.cs, or your custom extension method analogous to it.
Prerequisites
- You use Microsoft.Extensions.DependencyInjection to register services
- You use default
ConfigureServices
in Startup.cs and/or custom extension methods to register services with following signature:
public static class Module
{
public static IServiceCollection RegisterServices(this IServiceCollection services)
{
return services.AddSingleton<Foo>()
...
;
}
}
Installation
It can be installed in any project through nuget package
Features
- Code Actions with AddSingleton|AddScoped|AddTransient methods with appropriate type parameters will be inferred from your class declaration.
- First base type in your class declaration will be used as a first type argument in extension method call.
- Code action will add registration onto first line of nearest registration method with separate statement
services.AddX<IFoo, Foo>();
. - You can annotate method which follows convention, but you don't want to be considered as RegistrationMethod with
[IgnoreRegistrationMethod]
attribute. - You can annotate method which does not follow convention, but you want it to be considered as RegistrationMethod with
[RegistrationMethod]
attribute. - Add required using if it is not yet added
- Code action will add registration into
return services.AddX<Foo>().AddX<Bar>()
invocation chain. - You can trigger refactoring on a specific item in your class' base list, and it will register method as such base.
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.