Dependency Injection

DbSyncKit can be configured using Dependency Injection (DI) to manage the application's services more efficiently. This guide outlines the steps to set up DbSyncKit with DI in your application.

1. Add DbSyncKit Services

To configure DbSyncKit with Dependency Injection, add the necessary services to your DI container.

API Reference: SynchronizationServiceCollectionExtensions

services.AddSynchronizationServices();

This method adds the required DbSyncKit services to the IServiceCollection.

2. Inject Synchronization

Once the services are added, you can inject the Synchronization class into your application components.

API Reference: Synchronization

public class YourService
{
    private readonly Synchronization _sync;

    public YourService(Synchronization sync)
    {
        _sync = sync;
    }

    // Use _sync for synchronization tasks
}

Now, you can use the injected Synchronization instance in your services to perform synchronization tasks.

3. Database Configuration

Configure your source and destination databases using DbSyncKit's IDatabase interface.

For MSSQL

Api Ref: Connection

// MSSQL manual database configuration
IDatabase SourceDatabase = new DbSyncKit.MSSQL.Connection("(localdb)\\MSSQLLocalDB", true, "SourceChinook");
IDatabase DestinationDatabase = new DbSyncKit.MSSQL.Connection("(localdb)\\MSSQLLocalDB", true, "DestinationChinook");

For MySQL

Api Ref: Connection

// MySQL manual database configuration
IDatabase SourceDatabase = new DbSyncKit.MySQL.Connection("localhost", 3306, "SourceChinook", "root", "");
IDatabase DestinationDatabase = new DbSyncKit.MySQL.Connection("localhost", 3306, "DestinationChinook", "root", "");

For PostgreSQL

Api Ref: Connection

// PostgreSQL manual database configuration
IDatabase SourceDatabase = new DbSyncKit.PostgreSQL.Connection("localhost", 5432, "sourceChinook", "postgres", "");
IDatabase DestinationDatabase = new DbSyncKit.PostgreSQL.Connection("localhost", 5432, "destinationChinook", "postgres", "");

For SQLite

Api Ref: Connection

// SQLite manual database configuration
IDatabase SourceDatabase = new DbSyncKit.SQLite.Connection(Path.Combine("Path", "to", "sourceChinook.sqlite"));
IDatabase DestinationDatabase = new DbSyncKit.SQLite.Connection(Path.Combine("Path", "to", "destinationChinook.sqlite"));

Replace connection strings and other details according to your actual configurations.

Next Steps

You have now successfully set up DbSyncKit with Dependency Injection. Proceed to the Usage Guide to learn how to perform synchronization tasks with DbSyncKit.