DependencyInjection.SourceGenerator.LightInject 1.2.2-alpha2

This is a prerelease version of DependencyInjection.SourceGenerator.LightInject.
There is a newer version of this package available.
See the version list below for details.
dotnet add package DependencyInjection.SourceGenerator.LightInject --version 1.2.2-alpha2
                    
NuGet\Install-Package DependencyInjection.SourceGenerator.LightInject -Version 1.2.2-alpha2
                    
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="DependencyInjection.SourceGenerator.LightInject" Version="1.2.2-alpha2">
  <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.
<PackageVersion Include="DependencyInjection.SourceGenerator.LightInject" Version="1.2.2-alpha2" />
                    
Directory.Packages.props
<PackageReference Include="DependencyInjection.SourceGenerator.LightInject">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DependencyInjection.SourceGenerator.LightInject --version 1.2.2-alpha2
                    
#r "nuget: DependencyInjection.SourceGenerator.LightInject, 1.2.2-alpha2"
                    
#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.
#addin nuget:?package=DependencyInjection.SourceGenerator.LightInject&version=1.2.2-alpha2&prerelease
                    
Install DependencyInjection.SourceGenerator.LightInject as a Cake Addin
#tool nuget:?package=DependencyInjection.SourceGenerator.LightInject&version=1.2.2-alpha2&prerelease
                    
Install DependencyInjection.SourceGenerator.LightInject as a Cake Tool

DependencyInjection.SourceGenerator.LightInject

Register services using attributes instead of registering in code.

Usage

Add the "Register" attribute to the class you want to register. The attribute takes a type and a lifetime. The type is the type you want to register and the lifetime is the lifetime of the service. The lifetime is optional and defaults to Transient.

var services = new ServiceCollection();
services.AddMyProject();

### LightInject

```csharp
[Register(ServiceName = "ServiceName", Lifetime = Lifetime.Singleton)]
public class ExampleService : IExampleService
{
	public string GetExample()
	{
		return "Example";
	}
}

public interface IExampleService
{
	string GetExample();
}

Generates a class CompositionRoot

public class CompositionRoot : ICompositionRoot
{
	public static void Compose(IServiceRegistry serviceRegistry)
	{
		serviceRegistry.Register<IExampleService, ExampleService>("ServiceName", new PerContainerLifetime());
	}
}

If you already have a class CompositionRoot defined, the generated class will be made partial. Remeber to make your CompositionRoot partial as well. It will also call a method RegisterServices on the existing CompositionRoot class (this must be defined).

public partial class CompositionRoot : ICompositionRoot
{
	public static void Compose(IServiceRegistry serviceRegistry)
	{
		RegisterServices(serviceRegistry);
		serviceRegistry.Register<IExampleService, ExampleService>("ServiceName", new PerContainerLifetime());
	}
}

The final existing CompositionRoot class must look like this:

public partial class CompositionRoot
{
	public void RegisterServices(IServiceRegistry serviceRegistry)
	{
		// Register services here
	}
}

Lifetime

The lifetime is an enum with the following values:

  • Transient
  • Scoped
  • Singleton
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • 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.

Version Downloads Last updated
2.0.0 193 8/30/2024
1.6.0 215 2/14/2024
1.5.1 202 1/15/2024
1.5.0 142 1/15/2024
1.4.3 164 1/10/2024
1.4.2 136 1/10/2024
1.4.1 142 1/9/2024
1.4.0 149 1/9/2024
1.3.3 163 1/8/2024
1.3.2 131 1/8/2024
1.3.1 129 1/8/2024
1.3.0 141 1/8/2024
1.2.2 162 1/8/2024
1.2.2-alpha3 94 1/8/2024
1.2.2-alpha2 134 1/8/2024
1.2.1 126 1/5/2024
1.2.1-alpha6 171 1/5/2024
1.2.1-alpha5 104 1/5/2024
1.2.1-alpha2 101 1/5/2024
1.2.1-alpha1 137 1/5/2024
1.2.0 128 1/5/2024
1.1.2 139 1/5/2024
1.1.1 111 1/5/2024
1.1.0 164 1/5/2024
1.0.2 150 1/5/2024
1.0.1 138 1/4/2024
1.0.0 149 1/4/2024