假设我有一个连接到n数据库的Windows窗体应用程序,n同时打开连接.
我正在寻找的是一次性与所有这些数据库进行交易.
例如,如果我有2个数据库连接:
using (ITransaction tx1 = session1.OpenTransaction())
{
using (ITransaction tx2 = session2.OpenTransaction())
{
// Do the query thingy here
}
}
Run Code Online (Sandbox Code Playgroud)
写一切都很好,但是当我想在这里和那里查询时,事情变得多余,更不用说添加新连接的可能性了.
我想要的是循环所有已注册的会话并将其包装在服务中,可能是这样的:
class TransactionManager
{
private ISession[] _sessions;
public TransactionManager(string[] connectionStrings)
{
// Initialize the sessions here
}
public function DoTransaction(string query)
{
foreach (ISession session in _sessions)
{
// What to do here? Using? Try-catch?
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在foreach循环中使用use ,则意味着如果连接A成功但连接B不成功,那么只有连接B将被回滚.
我只是想了解PostSharp,说实话,我认为这太棒了.
但有一件事我很难在PostSharp方面无法完成纯依赖注入(不是服务定位器),也许是因为编译时编织的结果.
来自PHP背景,Symfony有JMSAopBundle,它仍然允许依赖注入它的拦截器.
.Net是否有一些具有相同功能的库?
或者我错过了PostSharp的东西?
我最近使用依赖注入模式和Autofac作为IoC容器.
通常,我会在核心应用程序(Winform,WCF,WPF等)中使用它.
目前我正在学习创建一个类库项目作为我的同行开发人员的框架,我倾向于坚持DI模式,因为它允许我进行单元测试.
如何在没有入口点的类库项目中配置IoC容器?
我应该做的事情如下:
public static void ConfigureLibrary() {
//.. Do bootstraping here
}
Run Code Online (Sandbox Code Playgroud)
并让核心应用程序在核心应用程序启动时调用它?
如何配置模式和实践企业库或Spring.Net的库?
.net c# dependency-injection class-library inversion-of-control
我开始研究一个新项目,我来自一个直接的,"天真"的编程.
现在我关心使用IoC容器,特别是使用Autofac的依赖注入模式.
假设我有一个简单的会话工厂:
namespace Warehouse.Data
{
public class SessionFactory
{
private static ISessionFactory _sessionFactory;
private static ISystemSetting _systemSetting;
SessionFactory(ISystemSetting systemSetting)
{
_systemSetting = systemSetting;
InitializeSessionFactory();
}
private static void InitializeSessionFactory()
{
_sessionFactory = Fluently.Configure()
.Database(DatabaseConfiguration)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyMap>())
.BuildSessionFactory();
}
public static ISession OpenSession()
{
return _sessionFactory.OpenSession();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Bootstrap.cs中,我像这样配置autofac:
namespace Warehouse.Infrastructure
{
using Autofac;
public class Bootstrap
{
public IContainer Configure()
{
var builder = new ContainerBuilder();
builder.RegisterType<SystemSetting>().As<ISystemSetting>();
builder.RegisterType<UserRepository>().As<IUserRepository>();
return builder.Build();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:
builder.Resolve<ISystemSetting>每次我想使用SessionFactory时,是否需要将其用作参数? …首先,在经过这么长时间的斗争之后,我无法理解MVVM模式的本质,我感到很惭愧,我不禁要问.
我搜索和搜索了MVVM,但是(我似乎)清楚的层只是View和ViewModel层.
所以这是我到目前为止所掌握的一些小例子,仅供我使用MySQL查询来获取我的数据:
模型
我不清楚在这做什么.我有这类Employee.cs:
class Employee
{
public string Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的问题:我应该在EmployeeModel类中从MySQL数据库中获取数据吗?我读到了这个答案,数据访问层与MVVM的模型不同,而且我可以使用存储库从我的数据访问层请求Employees列表.
根据答案,那应该是这样的:
对于一页员工名单的所有这些,我做错了什么?
很抱歉,如果我说错了,我会非常乐意解决这个问题.
我现在真的很无能,所以任何新鲜的观点都非常感激.
干杯!
因此,我已经开始尝试nuxt了,当时我需要axios,但无法使用nuxt的axios模块。
这是文件
nuxt.config.js
module.exports = {
generate: {
routes: ['/']
},
head: {
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Flynd FMS' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
loading: { color: '#3B8070' },
modules: [
'@nuxtjs/router',
'@nuxtjs/dotenv'
],
plugins: [
{src: '@/plugins/axios.js', ssr: true},
{src: '@/plugins/vuex-router-sync.js', ssr: false}
],
build: {
vendor: ['axios'],
extend (config, ctx) {
if …Run Code Online (Sandbox Code Playgroud) 我有一个简单的应用程序,显示了一个书籍列表.
BookViewModel.cs
public class BookViewModel : INotifyPropertyChanged
{
private readonly IBookRepository _bookRepository;
private bool _isDirty = false;
public ICommand UpdateCommand { get; set; }
public bool IsDirty { get { return _isDirty; } }
public BookViewModel(IBookRepository bookRepository)
{
_bookRepository = bookRepository;
UpdateCommand = new UpdateAction(this);
var books = _bookRepository.GetAll();
_allBooks = new ObservableCollection<BookModel>();
_allBooks.CollectionChanged += collectionChanged;
foreach (var book in books)
{
_allBooks.Add(new BookModel()
{
Title = book.Title,
Stock = book.Stock
});
}
}
private ObservableCollection<BookModel> _allBooks;
private BookModel _book; …Run Code Online (Sandbox Code Playgroud) 我在从属端的MySQL复制有错误22,特别是关于charset错误.
该错误表明它找不到charset'#45',我发现它很奇怪,因为使用的查询是陈述的DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci,我确实检查了charset\Index.xml它确实存在.
师父: Server version: 5.5.30-log
奴隶 : Server version: 5.1.66-log
当前复制状态:
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.10.2.21
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000024
Read_Master_Log_Pos: 1065715871
Relay_Log_File: mysqld-relay-bin.000029
Relay_Log_Pos: 86980698
Relay_Master_Log_File: mysql-bin.000024
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 22
Last_Error: Error 'Character set '#45' is not a compiled character set and is …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×5
mvvm ×2
wpf ×2
axios ×1
data-binding ×1
master-slave ×1
mysql ×1
nuxt.js ×1
postsharp ×1
replication ×1
structure ×1
vb.net ×1
vue.js ×1