HtmlCssToImage.DependencyInjection
0.0.9
dotnet add package HtmlCssToImage.DependencyInjection --version 0.0.9
NuGet\Install-Package HtmlCssToImage.DependencyInjection -Version 0.0.9
<PackageReference Include="HtmlCssToImage.DependencyInjection" Version="0.0.9" />
<PackageVersion Include="HtmlCssToImage.DependencyInjection" Version="0.0.9" />
<PackageReference Include="HtmlCssToImage.DependencyInjection" />
paket add HtmlCssToImage.DependencyInjection --version 0.0.9
#r "nuget: HtmlCssToImage.DependencyInjection, 0.0.9"
#:package HtmlCssToImage.DependencyInjection@0.0.9
#addin nuget:?package=HtmlCssToImage.DependencyInjection&version=0.0.9
#tool nuget:?package=HtmlCssToImage.DependencyInjection&version=0.0.9
HTML/CSS to Image
.NET / C# Client - Dependency Injection

This package provides dependency injection support for the HtmlCssToImage client.
Getting Started
Installation
Add the package to your project:
dotnet add package HtmlCssToImage.DependencyInjection
Registering the IHtmlCssToImageClient in your application's startup
(usually Program.cs or Startup.cs)
You can provide your API Id and Key directly or using standard dotnet Configuration.
Direct Configuration
If you want to provide your API Id and Key directly, you can do so by calling AddHtmlCssToImage in your Program.cs or Startup.cs - this may be useful for testing purposes locally, but it is not recommended to use plain text credentials in your source code in production.
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHtmlCssToImage("api_id", "api_key");
}
}
Action-based Configuration
To provide your API Id and Key using an action, you can call AddHtmlCssToImage in your Program.cs or Startup.cs and pass in an action that will be invoked to retrieve your API Id and Key.
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHtmlCssToImage(options =>
{
options.ApiId = Environment.GetEnvironmentVariable("HCTI_API_ID")!;
options.ApiKey = Environment.GetEnvironmentVariable("HCTI_API_KEY")!;
});
}
}
Standard dotnet Configuration
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHtmlCssToImage(builder.Configuration.GetSection("HCTI"));
}
}
You can also simply pass a string to the AddHtmlCssToImage method to bind to a configuration section.
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHtmlCssToImage("HCTI");
}
}
In either case, your configuration would look like this:
{
"HCTI":{
"ApiId": "api_id",
"ApiKey": "api_key"
}
}
See HtmlCssToImageOptions.cs for the Configuration object
HTTP Options
Because the HtmlCssToImage client is added to the DI container as a typed HTTP Client (see Microsoft Docs) it means you can extend its default behavior, such as adding retry policies or logging.
All the .AddHtmlCssToImage() methods return an IHttpClientBuilder which allows you to configure the underlying HttpClient instance.
Performance & Native AOT
This library is built with performance in mind and is fully compatible with Native AOT (Ahead-of-Time) compilation in .NET 9+.
The client internally uses source-generated JSON serialization, so no extra configuration is required for standard API requests.
The configuration binding source generator is enabled, so you can safely use the IConfiguration overload of AddHtmlCssToImage without any additional configuration. You still need to ensure that the PublishAot flag is enabled in your project file.
Check out the HTML/CSS To Image Docs for more details on the API's capabilities.
Get started for free at htmlcsstoimage.com.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- HtmlCssToImage (>= 0.0.9)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.1)
-
net9.0
- HtmlCssToImage (>= 0.0.9)
- Microsoft.Extensions.DependencyInjection (>= 9.0.11)
- Microsoft.Extensions.Http (>= 9.0.11)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on HtmlCssToImage.DependencyInjection:
| Package | Downloads |
|---|---|
|
HtmlCssToImage.Blazor
Official Blazor integration for HTML/CSS to Image API. Add automated OG meta tags to your pages. |
|
|
HtmlCssToImage.TagHelpers
Official Tag Helpers for HTML/CSS to Image API. Add automated OG meta tags to your pages. |
GitHub repositories
This package is not used by any popular GitHub repositories.