Skip to main content

IJsonDataConnectionProviderService Interface

Defines a service that resolves a JSON connection by name.

Namespace: DevExpress.DataAccess.Json

Assembly: DevExpress.DataAccess.v24.1.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap

Declaration

public interface IJsonDataConnectionProviderService

The following members return IJsonDataConnectionProviderService objects:

Remarks

A JSON data source can use a custom connection service for the JSON data source to obtain a connection string by its name.

The following code retrieves a connection string from the dictionary for the given connection name, creates and returns the JsonDataConnection object.

using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.DataAccess.Json;
using DevExpress.DataAccess.Web;
using ReportWizardCustomizationServiceAspNetCoreExample.Data;

namespace ReportWizardCustomizationServiceAspNetCoreExample.Services
{
    public class CustomJsonDataConnectionProviderFactory : IJsonDataConnectionProviderFactory {
        protected ReportDbContext DbContext { get; }

        public CustomJsonDataConnectionProviderFactory(ReportDbContext dbContext) {
            DbContext = dbContext;
        }

        public IJsonDataConnectionProviderService Create() {
            return new WebDocumentViewerJsonDataConnectionProvider(DbContext.JsonDataConnections.ToList());
        }
    }

    public class WebDocumentViewerJsonDataConnectionProvider : IJsonDataConnectionProviderService
    {
        readonly IEnumerable<DataConnection> jsonDataConnections;
        public WebDocumentViewerJsonDataConnectionProvider(IEnumerable<DataConnection> jsonDataConnections) {
            this.jsonDataConnections = jsonDataConnections;
        }
        public JsonDataConnection GetJsonDataConnection(string name) {
            var connection = jsonDataConnections.FirstOrDefault(x => x.Name == name);
            if(connection == null)
                throw new InvalidOperationException();
            return CustomDataSourceWizardJsonDataConnectionStorage.CreateJsonDataConnectionFromString(connection);
        }
    }
}

For more information and code examples, review the following help topic: JSON Data - Register Connections.

See Also