LiteOrm.Remote
8.1.9
dotnet add package LiteOrm.Remote --version 8.1.9
NuGet\Install-Package LiteOrm.Remote -Version 8.1.9
<PackageReference Include="LiteOrm.Remote" Version="8.1.9" />
<PackageVersion Include="LiteOrm.Remote" Version="8.1.9" />
<PackageReference Include="LiteOrm.Remote" />
paket add LiteOrm.Remote --version 8.1.9
#r "nuget: LiteOrm.Remote, 8.1.9"
#:package LiteOrm.Remote@8.1.9
#addin nuget:?package=LiteOrm.Remote&version=8.1.9
#tool nuget:?package=LiteOrm.Remote&version=8.1.9
LiteOrm.Remote
📖 English Version
LiteOrm.Remote is the client-side package of LiteOrm's remote service invocation. It generates dynamic proxies for your service interfaces and forwards calls over HTTP to a LiteOrm.Remote.Server endpoint, so business code can call remote services exactly like local ones.
When to Use
- You want to physically separate frontend apps (Web / desktop / mobile) from the database access layer.
- Multiple clients need to share one backend service implementation.
- You need to keep database connection strings off the client machines.
Requirements
- .NET 8.0+ / .NET Standard 2.0 (.NET Framework 4.6.1+ compatible)
- Dependencies:
LiteOrm.Common,Castle.Core,Castle.Core.AsyncInterceptor - A running
LiteOrm.Remote.Serverendpoint to forward calls to
Installation
dotnet add package LiteOrm.Remote
Quick Start
using LiteOrm.Remote;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddLiteOrmRemote(opts =>
{
opts.RemoteServiceUri = new Uri("http://localhost:5000");
});
var host = builder.Build();
For authenticated connections, use StaticCredentialsResolver to obtain a ticket from the server's SignIn endpoint:
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddLiteOrmRemote(opts =>
{
opts.RemoteServiceUri = new Uri("http://localhost:5000");
// Register StaticCredentialsResolver via factory
opts.CredentialsResolverFactory = sp =>
{
var httpClient = new HttpClient { BaseAddress = opts.RemoteServiceUri };
return new StaticCredentialsResolver(httpClient, opts.RemoteSignInPath);
};
});
var host = builder.Build();
// Log in once at startup (resolve the resolver from the DI container)
using (var scope = host.Services.CreateScope())
{
var resolver = scope.ServiceProvider.GetRequiredService<ICredentialsResolver>();
await ((StaticCredentialsResolver)resolver).LoginAsync(new RemoteCredentials
{
Username = "admin",
Password = "pass",
});
}
HttpRemoteServiceTransport calls ICredentialsResolver.GetTicketAsync on each InvokeAsync and writes the ticket to the HTTP request header.
AutoRegisterEntityServices defaults to true — the framework scans interfaces marked with [Service] and registers them as remote proxies automatically. No per-interface registration needed.
Call Remote Services Like Local Ones
using var scope = host.Services.CreateScope();
var userService = scope.ServiceProvider.GetRequiredService<IDemoUserService>();
var user = new DemoUser { UserName = "alice" };
await userService.InsertAsync(user); // Id is written back automatically
Console.WriteLine($"Inserted user Id = {user.Id}");
Highlights
- Transparent RPC: dynamic proxies make remote calls look like local interface calls.
- Auto Identity Write-back:
ArgumentOutAttributecarries identity values back from the server. - Ticket-based Authentication:
ICredentialsResolverprovides an identity ticket on eachInvokeAsync, written to the HTTP request header (Cookie by default, orAuthorization: Bearerfor JWT). Built-inStaticCredentialsResolverhandles login for single-user scenarios. - Pluggable Transport: built-in HTTP transport; swap
IRemoteServiceTransportfor custom transports. - Shared Protocol: DTOs (
RemoteInvocationRequest/RemoteInvocationResponse) live inLiteOrm.Common, so client and server stay in sync.
📖 中文版本
LiteOrm.Remote 是 LiteOrm 远程服务调用的客户端包。它为服务接口生成动态代理,通过 HTTP 将调用转发到 LiteOrm.Remote.Server 端点,业务代码可以像调用本地服务一样调用远程服务。
适用场景
- 需要将前端应用(Web / 桌面 / 移动端)与数据访问层物理隔离。
- 多个客户端需要共享同一套后端服务实现。
- 希望数据库连接串不暴露在客户端机器上。
环境要求
- .NET 8.0+ / .NET Standard 2.0(兼容 .NET Framework 4.6.1+)
- 依赖库:
LiteOrm.Common、Castle.Core、Castle.Core.AsyncInterceptor - 需要一个运行中的
LiteOrm.Remote.Server端点接收调用
安装
dotnet add package LiteOrm.Remote
快速入门
using LiteOrm.Remote;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddLiteOrmRemote(opts =>
{
opts.RemoteServiceUri = new Uri("http://localhost:5000");
});
var host = builder.Build();
已认证连接需使用 StaticCredentialsResolver,从服务端 SignIn 端点获取票据:
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddLiteOrmRemote(opts =>
{
opts.RemoteServiceUri = new Uri("http://localhost:5000");
// 使用工厂注册 StaticCredentialsResolver
opts.CredentialsResolverFactory = sp =>
{
var httpClient = new HttpClient { BaseAddress = opts.RemoteServiceUri };
return new StaticCredentialsResolver(httpClient, opts.RemoteSignInPath);
};
});
var host = builder.Build();
// 启动时登录一次(从 DI 容器解析出 resolver 实例)
using (var scope = host.Services.CreateScope())
{
var resolver = scope.ServiceProvider.GetRequiredService<ICredentialsResolver>();
await ((StaticCredentialsResolver)resolver).LoginAsync(new RemoteCredentials
{
Username = "admin",
Password = "pass",
});
}
HttpRemoteServiceTransport 在每次 InvokeAsync 时调用 ICredentialsResolver.GetTicketAsync 获取票据并写入 HTTP 请求头。
AutoRegisterEntityServices 默认为 true,框架自动扫描带 [Service] 特性的接口并注册为远程代理,无需手动逐个注册。
像本地服务一样调用远程服务
using var scope = host.Services.CreateScope();
var userService = scope.ServiceProvider.GetRequiredService<IDemoUserService>();
var user = new DemoUser { UserName = "alice" };
await userService.InsertAsync(user); // Id 自动回写
Console.WriteLine($"新增用户 Id = {user.Id}");
主要特性
- 透明 RPC:动态代理让远程调用看起来与本地接口调用无异。
- 自动 Identity 回写:通过
ArgumentOutAttribute把服务端生成的标识值回写到客户端。 - 票据身份认证:
ICredentialsResolver在每次InvokeAsync时提供身份票据并写入 HTTP 请求头(默认 Cookie,JWT 场景可改为Authorization: Bearer)。内置StaticCredentialsResolver处理单用户场景的登录。 - 可插拔传输层:内置 HTTP 传输;可实现
IRemoteServiceTransport替换为自定义传输。 - 共享协议:DTO(
RemoteInvocationRequest/RemoteInvocationResponse)位于LiteOrm.Common,客户端与服务端协议天然一致。
📚 相关资源 / Resources
- LiteOrm 主仓库 / Main Repository
- 远程服务文档 / Remote Service Docs
- 服务端包 / Server Package: LiteOrm.Remote.Server
- Demo 项目 / Demo Project
📄 License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Castle.Core (>= 5.2.1)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- LiteOrm.Common (>= 8.1.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Logging.Abstractions (>= 2.2.0)
-
.NETStandard 2.1
- Castle.Core (>= 5.2.1)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- LiteOrm.Common (>= 8.1.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Logging.Abstractions (>= 2.2.0)
-
net10.0
- Castle.Core (>= 5.2.1)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- LiteOrm.Common (>= 8.1.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
-
net8.0
- Castle.Core (>= 5.2.1)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- LiteOrm.Common (>= 8.1.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
8.1.9:
- 同步 LiteOrm.Common 8.1.9 / LiteOrm 8.1.9。