ServiceStack - 使用自定义注册?
ServiceStack - use customized registration?
我创建了一个自定义用户 table 用于身份验证。当我尝试注册用户时,内置 registerservice.cs 转到 UserAuth 所以
""ResponseStatus": {
"ErrorCode": "InvalidCastException",
"Message": "Unable to cast object of type 'ServiceStack.Auth.UserAuth' to type 'SOS.Api.ServiceModel.Types.User'.","
被抛出。我知道我可以扩展 registerservice.cs,但我如何使用自定义的 .cs?在 AppHost.cs
Plugins.Add(new RegistrationFeature());
之类的?谢谢
ServiceStack 的 RegisterService 绑定到内置 UserAuth
模型,即:
[DefaultRequest(typeof(Register))]
public class RegisterService : RegisterUserAuthServiceBase {}
您需要提供自己的自定义注册服务来处理您可以注册的自定义 Poco:
[DefaultRequest(typeof(Register))]
public class CustomRegisterService : RegisterUserAuthServiceBase {}
由于这是一个不同的注册服务,您不想启用 ServiceStack 的内置 RegistrationFeature:
//Plugins.Add(new RegistrationFeature()); //don't register this plugin
您应该改为在您的 AppHost 中手动注册您的服务:
this.RegisterService<CustomRegisterService>("/register");
this.RegisterAs<RegistrationValidator, IValidator<Register>>();
使用修改后的副本
由于 RegisterService 相当轻量级,另一种选择是复制它并修改它以引用您的 CustomUserAuth POCO。
我创建了一个自定义用户 table 用于身份验证。当我尝试注册用户时,内置 registerservice.cs 转到 UserAuth 所以
""ResponseStatus": {
"ErrorCode": "InvalidCastException",
"Message": "Unable to cast object of type 'ServiceStack.Auth.UserAuth' to type 'SOS.Api.ServiceModel.Types.User'.","
被抛出。我知道我可以扩展 registerservice.cs,但我如何使用自定义的 .cs?在 AppHost.cs
Plugins.Add(new RegistrationFeature());
之类的?谢谢
ServiceStack 的 RegisterService 绑定到内置 UserAuth
模型,即:
[DefaultRequest(typeof(Register))]
public class RegisterService : RegisterUserAuthServiceBase {}
您需要提供自己的自定义注册服务来处理您可以注册的自定义 Poco:
[DefaultRequest(typeof(Register))]
public class CustomRegisterService : RegisterUserAuthServiceBase {}
由于这是一个不同的注册服务,您不想启用 ServiceStack 的内置 RegistrationFeature:
//Plugins.Add(new RegistrationFeature()); //don't register this plugin
您应该改为在您的 AppHost 中手动注册您的服务:
this.RegisterService<CustomRegisterService>("/register");
this.RegisterAs<RegistrationValidator, IValidator<Register>>();
使用修改后的副本
由于 RegisterService 相当轻量级,另一种选择是复制它并修改它以引用您的 CustomUserAuth POCO。