## Documentation

- About
- Read First
  - What is IdentityServer
  - Installation Scenarios
- Migrations
- Bootstrapping
- Configuration & Integration
  - AdminUI Settings
  - Configuring AdminUI
  - Configuring AdminUI (NuGet)
  - Integrating with Identity Server
  - Integrating with Identity Server Custom Schema
  - Integrating with Quickstarts
  - Enabling Logging
- Installation
  - Installer
  - IIS
  - Azure
    - Install in Azure
    - Create Azure Web App
  - Docker
  - NuGet
- Custom Database Connections
- Custom Identity Store
  - Overview
  - Partial Implementation
  - Full Implementation
  - Tenancy With Entity Framework
  - NoSql Implementation (MongoDB)
- Custom CSP
- Users
  - Searching for Users
  - Adding Users
  - Editing Users
  - Deleting Users
  - Merge Users
  - Set User Password
  - Session Management
  - User Reports
  - Bulk User Import
- Roles
  - Creating Roles
  - Managing Roles
  - Managing Users in a Role
  - Managing Role Claims
- Claim Types
- Clients
  - Searching for Clients
  - Adding Clients
  - Adding a SAML Client
  - Adding a WS-Fed Client
  - Editing Clients
  - Deleting Clients
  - Clone Client
- Import and Export
  - Exporting Clients
  - Importing Clients
  - Importing Client Configuration with Secrets
  - Importing SAML Clients with Certificates
  - Import and Export Via the API
- Dynamic Authentication Providers
  - What is Dynamic Authentication
  - Enabling or disabling Dynamic Authentication
  - Add a Dynamic Provider
    - First Steps
    - Adding OIDC Provider
    - Adding SAML Provider
  - Edit a Dynamic Provider
    - Accessing edit view
    - Editing a OIDC Provider
    - Editing a SAML Provider
  - Deleting a Provider
  - Searching for Provider
- Resources
  - Searching for Resources
  - Creating Resources
  - Editing resources
- Webhooks
  - Webhooks
  - Endpoint Configuration
- User Settings Endpoints
- Access Policy
- Keys
- Auditing
- FAQs
- Troubleshooting
  - Unable to start AdminUI
  - Unable to contact IdentityServer
  - Unable to contact API
  - Unable to log in

### Custom Database Connections

- -Overview
- -Changes
- -Starting point
- -Additional Considerations
- -Sample code

## Overview

This page assumes you have read the AdminUI as a NuGet package documentation area.

The AdminUI NuGet package uses a factory abstraction for creating database connections. When using the AdminUI NuGet package in your web applications, you can use the default implementation. This uses connection strings in configuration to create the connection. The connection strings it uses are in appSettings.json and cover 5 different areas of functionality:

      "IdentityConnectionString": "...",
      "IdentityServerConnectionString": "...",
      "OperationalConnectionString": "...",
      "AuditRecordsConnectionString": "...",
      "DataProtectionConnectionString": "...",

You can get away with just using the first 2 as the last 3 will default to the second one. See here for more details.

Alternatively, you can write your own connection factory implementation to create connections using a different strategy. This opens up AdminUI to users who may have not been able to take advantage of it in the past - perhaps users who deploy AdminUI in Azure and authenticates with the database via an Azure AD token.

### Changes

As mentioned above, AdminUI’s connection creation has historically been based purely on using connection strings.

AdminUI 6.7 adds a pluggable abstraction that allows for the decoupling from this old strategy.

The abstraction is `IDatabaseConnectionFactory` and it is initialized in AdminUI's service layer with the default implementation. The interface is defined thus:

    public interface IDatabaseConnectionFactory
    {
         // Create connection for the Identity database (Users, Claim Types, Roles etc.)
        public DbConnection CreateIdentityConnection(bool migration = false);

        // Create connection for the IdentityServer database (Clients, Resources, Persited Grants etc.)
        public DbConnection CreateIdentityServerConnection(bool migration = false);

        // Create connection for the Auditing DbContext
        public DbConnection CreateAuditRecordsConnection(bool migration = false);

        // Create connection for the Persisted Grants DbContext
        public DbConnection CreateOperationalConnection(bool migration = false);

        // Creates connection for the DataProtectionKey DbContext
        public DbConnection CreateDataProtectionConnection(bool migration = false);
    }

The `migration` parameter in each method is used to distinguish whether the method is called by AdminUI as part of its normal operation or when running migrations (in case you need to distinguish).

To change the default implementation, simply implement this interface and tell AdminUI to use it instead of the default.

## Starting point

To get started, take the result of the NuGet Installation and update the service registration to the following:

    builder.Services
        .AddAdminUI(
            options =>
            {
                options.DatabaseConnectionFactoryType = DatabaseConnectionFactoryType.Custom;
            })
        .WithConnectionFactory<MyCustomConnectionFactory>();

The `WithConnectionFactory<MyCustomConnectionFactory>()` method replaces the default connection factory implementation with that defined by `MyCustomConnectionFactory` class that you write.

That's it!

## Additional Considerations

If the custom connection factory has additional interfaces injected into its constructor that are unknown to AdminUI then these will have to be registered with the DI container in the usual way using `builder.Services`, for example, if your custom connection factory implementation looks like this:

    public class MyCustomConnectionFactory : IDatabaseConnectionFactory
    {
        public MyCustomConnectionFactory(IConfiguration configuration, IMyOtherInterface myOtherInterface)
        {
            ...
        }

        ...
    }

then the service registration might look like this:

    builder.Services.AddSingleton<IMyOtherInterface, MyOtherInterfaceImplementation>();
    builder.Services
        .AddAdminUI(
            options =>
            {
                options.DatabaseConnectionFactoryType = DatabaseConnectionFactoryType.Custom;
            })
        .WithConnectionFactory<MyCustomConnectionFactory>();

## Sample code

A sample of how to replace the connection factory can be found on our GitHub in the `CustomDatabaseConnection` project. Remember to fill in the `CustomConnectionFactoryConnectionString` connection string and the license key in `appSettings.json`.

Previous Next