NuGet Installation
Install Hyppot directly in your .NET application using NuGet packages. This approach provides the deepest integration and adds more flexibility to adjust the configuration to fit your needs.
Prerequisites
- .NET 8.0 or later
- ASP.NET Core application
- SQL Server, PostgreSQL, or SQLite database
Installation Steps
1. Install NuGet Packages
Install the core package and your preferred database provider:
# Core package
dotnet add package Hyppot.AspNetCore
# Choose one database provider:
dotnet add package Hyppot.Sqlite # For SQLite
dotnet add package Hyppot.Postgresql # For PostgreSQL
dotnet add package Hyppot.Sqlserver # For SQL Server
2. Configure Services
Add Hyppot to your Program.cs
:
using Hyppot.AspnetCore;
using Hyppot.Sqlite; // or Hyppot.Postgresql / Hyppot.Sqlserver
var builder = WebApplication.CreateBuilder(args);
// Configure authorization policy for Hyppot admin panel
builder.Services.AddAuthorization(options =>
{
options.AddPolicy(HyppotConstants.DefaultAdminAuthorizationPolicyName, policy =>
policy.RequireRole("Admin")); // Customize as needed
});
// Configure Hyppot
builder.Services.AddHyppot(config =>
{
// Database setup (choose one)
config.DbSetup = new SqliteDbSetup("Data Source=hyppot.db");
// config.DbSetup = new PostgreSqlDbSetup("Host=localhost;Database=hyppotdb;Username=postgres;Password=password");
// config.DbSetup = new SqlServerDbSetup("Server=localhost;Database=HyppotDb;Trusted_Connection=true;");
// Optional: Custom path prefix (default is "hyppot")
// config.PathPrefix = "ab-testing";
});
var app = builder.Build();
// Add Hyppot middleware
app.UseHyppot();
app.Run();
3. Configure Authorization
Set up authorization for the admin panel. You can use any ASP.NET Core authorization policy:
// Role-based authorization
builder.Services.AddAuthorization(options =>
{
options.AddPolicy(HyppotConstants.DefaultAdminAuthorizationPolicyName, policy =>
policy.RequireRole("Admin"));
});
// Claim-based authorization
builder.Services.AddAuthorization(options =>
{
options.AddPolicy(HyppotConstants.DefaultAdminAuthorizationPolicyName, policy =>
policy.RequireClaim("permission", "hyppot.admin"));
});
// Custom authorization
builder.Services.AddAuthorization(options =>
{
options.AddPolicy(HyppotConstants.DefaultAdminAuthorizationPolicyName, policy =>
policy.RequireAssertion(context =>
context.User.Identity.IsAuthenticated &&
context.User.HasClaim("role", "admin")));
});
Verify Installation
- Run your application
- Access the admin panel at
https://your-app.url/hyppot/panel
Using Vite or other dev server for your local development? Remember to add proxying from your frontend SPA. For example, with Vite, you can add the following configuration to your vite.config.js
file:
// vite.config.js
export default defineConfig({
server: {
proxy: {
'^/hyppot/': {
"https://localhost:{YOUR_BACKEND_PORT}/",
secure: false
}
}
}
});
// Inject services
public class MyController : ControllerBase
{
private readonly IExperimentationResolver _resolver;
private readonly IExperimentTracker _tracker;
public MyController(
IExperimentationResolver resolver,
IExperimentTracker tracker)
{
_resolver = resolver;
_tracker = tracker;
}
public async Task<IActionResult> GetFeature(string userId)
{
// Resolve experiment
var experiment = _resolver.ResolveForUser(
new ExperimentId("my-experiment"),
new UserId(userId));
if (experiment != null)
{
var featureEnabled = experiment.Variables
.First(v => v.Name == new VariableName("feature-enabled"))
.Value.Get<bool>();
// Track impression
await _tracker.TrackImpressionAsync(
ExperimentImpression.Create(
new ExperimentId("my-experiment"),
new VariantId(experiment.VariantId),
new UserId(userId),
DateTime.UtcNow));
return Ok(new { featureEnabled });
}
return Ok(new { featureEnabled = false });
}
}
Next Steps
Once installed, you can define your first front-end experiment or use the .NET SDK in your application:
- Create your first experiment - Learn how to set up A/B tests
- Use the .NET SDK - Integrate experiments in your backend code
- Add JavaScript integration - Add frontend experiments
- Configure for production - Set up proper security and monitoring