csharp SQLite数据库到SQLServer同步的简单依赖注入
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp SQLite数据库到SQLServer同步的简单依赖注入相关的知识,希望对你有一定的参考价值。
using System.Data;
namespace Senkronizer.Abstractions {
public interface ISynchronizer {
IDbConnection LocalConnection { get; set; }
IDbConnection RemoteConnection { get; set; }
}
public abstract class BaseSynchronizer : ISynchronizer {
public IDbConnection LocalConnection { get; set; }
public IDbConnection RemoteConnection { get; set; }
protected BaseSynchronizer (IDbConnection localConnection, IDbConnection remoteConnection) {
LocalConnection = localConnection;
RemoteConnection = remoteConnection;
}
}
}
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
using Ninject;
using Ninject.Syntax;
using Senkronizer.Abstractions;
namespace Senkronizers.Apps.Debug {
internal class Program {
private static void Main (string [] args) {
IKernel synchKernel = new StandardKernel();
IKernel localKernel = new StandardKernel();
IKernel remoteKernel = new StandardKernel();
localKernel.Bind<IDbConnection>().To<SQLiteConnection>();
remoteKernel.Bind<IDbConnection>().To<SqlConnection>();
synchKernel
.Bind<ISynchronizer>()
.To<DebugWriter>()
.WithConstructorArgument("localConnection", localKernel.Get<IDbConnection>())
.WithConstructorArgument("remoteConnection", localKernel.Get<IDbConnection>());
synchKernel.Bind<IDbConnection>().To<SQLiteConnection>();
synchKernel.Bind<IDbConnection>().To<SQLiteConnection>();
var syncher = synchKernel.Get<ISynchronizer>();
System.Windows.Forms.Application.Run();
}
}
}
namespace Senkronizers {
using static System.Configuration.ConfigurationManager;
public class DebugWriter : BaseSynchronizer {
public DebugWriter (IDbConnection localConnection, IDbConnection remoteConnection) : base(localConnection, remoteConnection) {
LocalConnection.ConnectionString = ConnectionStrings ["local"].ConnectionString;
RemoteConnection.ConnectionString = ConnectionStrings ["remote"].ConnectionString;
}
}
}
以上是关于csharp SQLite数据库到SQLServer同步的简单依赖注入的主要内容,如果未能解决你的问题,请参考以下文章
将.db文件导入SQLServer2008数据库
一般问题处理记录(SqlServe)
如何用sqlserve连接mysql数据库
csharp SQLiteの书き込み速度アップ(SyncMode,JournalMode)
sqlserve 数据类型具体解释
Fluent NHibernate and Mysql,SQLite