dotenv.net.DependencyInjection.Autofac 2.1.1

Adds DI support for values read from the environment for Autofac

Install-Package dotenv.net.DependencyInjection.Autofac -Version 2.1.1
dotnet add package dotenv.net.DependencyInjection.Autofac --version 2.1.1
<PackageReference Include="dotenv.net.DependencyInjection.Autofac" Version="2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add dotenv.net.DependencyInjection.Autofac --version 2.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

dotenv.net

NuGet Badge

Usage

Conventional

First install the library as a dependency in your application from nuget

Install-Package dotenv.net.DependencyInjection.Autofac

or

dotnet add package dotenv.net.DependencyInjection.Autofac

or for paket

paket add dotenv.net.DependencyInjection.Autofac

Reading the Environment Variables

If using with ASP.NET Core or any other system that uses ContainerBuilder for its dependency injection, in the Startup.cs file

public void ConfigureContainer(ContainerBuilder containerBuilder)
{
  ...

  // configure dotenv
  containerBuilder.AddEnv(builder => {
      builder
      .AddEnvFile("/custom/path/to/your/env/vars")
      .AddThrowOnError(false)
      .AddEncoding(Encoding.ASCII);
  });
}

Injecting the EnvReader

If using with ASP.NET Core or any other system that uses ContainerBuilder for its dependency injection, in the Startup.cs file

public void ConfigureContainer(ContainerBuilder containerBuilder)
{
    ...

    // inject the env reader
    containerBuilder.AddEnvReader();
}

In a controller or service you can then inject the reader

...

public class StuffController: ControllerBase(IEnvReader envReader)
{
  // you can use the reader now to get specific variables by key
}

dotenv.net

NuGet Badge

Usage

Conventional

First install the library as a dependency in your application from nuget

Install-Package dotenv.net.DependencyInjection.Autofac

or

dotnet add package dotenv.net.DependencyInjection.Autofac

or for paket

paket add dotenv.net.DependencyInjection.Autofac

Reading the Environment Variables

If using with ASP.NET Core or any other system that uses ContainerBuilder for its dependency injection, in the Startup.cs file

public void ConfigureContainer(ContainerBuilder containerBuilder)
{
  ...

  // configure dotenv
  containerBuilder.AddEnv(builder => {
      builder
      .AddEnvFile("/custom/path/to/your/env/vars")
      .AddThrowOnError(false)
      .AddEncoding(Encoding.ASCII);
  });
}

Injecting the EnvReader

If using with ASP.NET Core or any other system that uses ContainerBuilder for its dependency injection, in the Startup.cs file

public void ConfigureContainer(ContainerBuilder containerBuilder)
{
    ...

    // inject the env reader
    containerBuilder.AddEnvReader();
}

In a controller or service you can then inject the reader

...

public class StuffController: ControllerBase(IEnvReader envReader)
{
  // you can use the reader now to get specific variables by key
}

Release Notes

- initial release

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.1.1 39 5/26/2020
2.1.0 81 4/1/2020