本文整理汇总了C#中IServiceBase.ResolveService方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceBase.ResolveService方法的具体用法?C# IServiceBase.ResolveService怎么用?C# IServiceBase.ResolveService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceBase
的用法示例。
在下文中一共展示了IServiceBase.ResolveService方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveOrUpdateRegistration
private void SaveOrUpdateRegistration(UserLoginType loginType, IServiceBase resolver, IOAuthTokens authToken, Dictionary<string, string> authInfo)
{
ViewContext context = resolver.ResolveService<ViewContext>();
CommandBus commandBus = resolver.ResolveService<CommandBus>();
IEntityIdGenerator entityIdGenerator = resolver.ResolveService<IEntityIdGenerator>();
Logger.Debug("Login type: {0}", loginType);
UserDocument existingUser = context.Users
.AsQueryable()
.FirstOrDefault(user => user.ThirdPartyId == authToken.UserId &&
user.LoginType == loginType);
if (existingUser != null)
{
UpdateUserRegistration command = new UpdateUserRegistration()
{
AggregateId = existingUser.Id,
FirstName = authInfo["first_name"],
LastName = authInfo["last_name"],
AccessToken = authToken.AccessToken,
PhotoSmallUri = authInfo["photo"],
PhotoBigUri = authInfo["photo_big"],
};
Logger.Info("Existing user: {0}", command.Dump());
UserId = existingUser.Id;
commandBus.Send(command, UserId);
}
else
{
RegisterUser command = new RegisterUser
{
AggregateId = entityIdGenerator.Generate(),
FirstName = authInfo["first_name"],
LastName = authInfo["last_name"],
LoginType = loginType,
ThirdPartyId = authToken.UserId,
AccessToken = authToken.AccessToken,
PhotoSmallUri = authInfo["photo"],
PhotoBigUri = authInfo["photo_big"]
};
Logger.Info("New user: {0}", command.Dump());
UserId = command.AggregateId;
commandBus.Send(command, UserId);
}
ICacheClient cacheClient = resolver.ResolveService<ICacheClient>();
UpdateSession(cacheClient);
}
示例2: OnAuthenticated
public override void OnAuthenticated(
IServiceBase authService,
IAuthSession session,
IOAuthTokens tokens,
Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
//Populate all matching fields from this session to your own custom User table
var user = session.TranslateTo<User>();
user.Id = int.Parse(session.UserAuthId);
//user.GravatarImageUrl64 = !session.Email.IsNullOrEmpty() ? CreateGravatarUrl(session.Email, 64) : null;
foreach (var authToken in session.ProviderOAuthAccess)
{
// //if (authToken.Provider == FacebookAuthProvider.Name)
// //{
// // user.FacebookName = authToken.DisplayName;
// // user.FacebookFirstName = authToken.FirstName;
// // user.FacebookLastName = authToken.LastName;
// // user.FacebookEmail = authToken.Email;
// //}
// //else
if (authToken.Provider == GoogleOpenIdOAuthProvider.Name)
{
user.GoogleUserId = authToken.UserId;
user.GoogleFullName = authToken.FullName;
user.GoogleEmail = authToken.Email;
if (user.Email == null) user.Email = user.GoogleEmail;
if (user.UserName == null) user.UserName = user.GoogleUserId;
}
else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
{
user.YahooUserId = authToken.UserId;
user.YahooFullName = authToken.FullName;
user.YahooEmail = authToken.Email;
}
}
var adminUserNames = AppHost.AppConfig.AdminUserNames;
if (AppHost.AppConfig.AdminUserNames.Contains(session.UserAuthName)
&& !session.HasRole(RoleNames.Admin))
{
using (var assignRoles = authService.ResolveService<AssignRolesService>())
{
assignRoles.Post(new AssignRoles
{
UserName = session.UserAuthName,
Roles = { RoleNames.Admin }
});
//authService.TryResolve<IDbConnectionFactory>().Run(db => db.Save(user));
}
}
//Resolve the DbFactory from the IOC and persist the user info
}