Added Viewer and
change to App Setting File from Constants
This commit is contained in:
29
Viewer/Repositories/SQLDbConnectionFactory.cs
Normal file
29
Viewer/Repositories/SQLDbConnectionFactory.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Viewer.Models;
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace OI.Metrology.Viewer.Repositories;
|
||||
|
||||
public class SQLDbConnectionFactory : IDbConnectionFactory
|
||||
{
|
||||
private readonly AppSettings _AppSettings;
|
||||
|
||||
public SQLDbConnectionFactory(AppSettings appSettings) => _AppSettings = appSettings;
|
||||
|
||||
public DbConnection GetDbConnection()
|
||||
{
|
||||
DbProviderFactories.RegisterFactory(
|
||||
typeof(SqlConnection).Namespace,
|
||||
SqlClientFactory.Instance);
|
||||
|
||||
if (string.IsNullOrEmpty(_AppSettings.ConnectionString))
|
||||
throw new Exception("Connection string is missing");
|
||||
|
||||
DbConnection c = SqlClientFactory.Instance.CreateConnection();
|
||||
c.ConnectionString = _AppSettings.ConnectionString;
|
||||
c.Open();
|
||||
return c;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user