corelibraries-devexpress-dot-dataaccess-dot-json-ec44075b.md
Defines a service that resolves a JSON connection by name.
Namespace : DevExpress.DataAccess.Json
Assembly : DevExpress.DataAccess.v25.2.dll
NuGet Package : DevExpress.DataAccess
public interface IJsonDataConnectionProviderService
Public Interface IJsonDataConnectionProviderService
The following members return IJsonDataConnectionProviderService objects:
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: Register JSON Data Connections (ASP.NET Core).
See Also
IJsonDataConnectionProviderService Members