SmartSql.CAP
No description available
Install / Use
/learn @xiangxiren/SmartSql.CAPREADME
SmartSql.CAP
Support CAP extension for SmartSql
Getting Started
Nuget
You can run the following command to install the SmartSql.CAP in your project.
PM> Install-Package SmartSql.CAP
Configuration
config SmartSql and CAP in your Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services
.AddSmartSql((provider, builder) => { builder.UseProperties(Configuration); })
.AddRepositoryFromAssembly(options => { options.AssemblyString = "Sample.Kafka.MySql"; })
.AddCapRepository();
services.AddCap(options =>
{
options.UseSmartSql();
options.UseKafka("localhost:9092");
options.UseDashboard();
});
}
Config SmartSqlMapConfig.xml
- MySql 8.0- (Not support
FOR UPDATE SKIP LOCKED)
<SmartSqlMaps>
<SmartSqlMap Path="Maps" Type="Directory"/>
<SmartSqlMap Path="SmartSql.CAP.Maps.CapMySql.xml,SmartSql.CAP" Type="Embedded" />
</SmartSqlMaps>
- MySql 8.0+ (Support
FOR UPDATE SKIP LOCKED)
<SmartSqlMaps>
<SmartSqlMap Path="Maps" Type="Directory"/>
<SmartSqlMap Path="SmartSql.CAP.Maps.CapMySql8.xml,SmartSql.CAP" Type="Embedded" />
</SmartSqlMaps>
- PostgreSQL
<SmartSqlMaps>
<SmartSqlMap Path="Maps" Type="Directory"/>
<SmartSqlMap Path="SmartSql.CAP.Maps.CapPostgreSql.xml,SmartSql.CAP" Type="Embedded" />
</SmartSqlMaps>
- MSSQL 2008
<SmartSqlMaps>
<SmartSqlMap Path="Maps" Type="Directory"/>
<SmartSqlMap Path="SmartSql.CAP.Maps.CapSqlServer2008.xml,SmartSql.CAP" Type="Embedded" />
</SmartSqlMaps>
- MSSQL 2012+
<SmartSqlMaps>
<SmartSqlMap Path="Maps" Type="Directory"/>
<SmartSqlMap Path="SmartSql.CAP.Maps.CapSqlServer.xml,SmartSql.CAP" Type="Embedded" />
</SmartSqlMaps>
Publish message With Transaction
public class UserService
{
private readonly IUserRepository _userRepository;
private readonly ICapPublisher _capBus;
public UserService(IUserRepository userRepository, ICapPublisher capPublisher)
{
_userRepository = userRepository;
_capBus = capPublisher;
}
[CapTransaction(AutoCommit = false)]
public virtual async Task AopAddAsync()
{
var person = new Person { Id = DateTime.Now.ToFileTimeUtc(), Name = "test1" };
await _repository.InsertAsync(person);
await _publisher.PublishAsync("sample.kafka.mysql", person.Id);
}
public async Task MtAddAsync()
{
using var trans = _repository.SqlMapper.BeginCapTransaction(_publisher);
var person = new Person { Id = DateTime.Now.ToFileTimeUtc(), Name = "test1" };
await _repository.InsertAsync(person);
await _publisher.PublishAsync("sample.kafka.mysql", person.Id);
await trans.CommitAsync();
}
public async Task MtAdd1Async()
{
await _repository.SqlMapper.CapTransactionWrapAsync(_publisher, async() =>
{
var person = new Person { Name = "test1" };
person.Id = await _repository.InsertAsync(person);
await _publisher.PublishAsync("sample.rabbitmq.mysql", person.Id);
});
}
}
Related Skills
feishu-drive
338.7k|
things-mac
338.7kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
338.7kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
yu-ai-agent
1.9k编程导航 2025 年 AI 开发实战新项目,基于 Spring Boot 3 + Java 21 + Spring AI 构建 AI 恋爱大师应用和 ReAct 模式自主规划智能体YuManus,覆盖 AI 大模型接入、Spring AI 核心特性、Prompt 工程和优化、RAG 检索增强、向量数据库、Tool Calling 工具调用、MCP 模型上下文协议、AI Agent 开发(Manas Java 实现)、Cursor AI 工具等核心知识。用一套教程将程序员必知必会的 AI 技术一网打尽,帮你成为 AI 时代企业的香饽饽,给你的简历和求职大幅增加竞争力。
