当前位置: 首页>>代码示例>>C#>>正文


C# IServiceBase.ResolveService方法代码示例

本文整理汇总了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);
        }
开发者ID:Ontropix,项目名称:whowhat,代码行数:54,代码来源:CustomUserSession.cs

示例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
        }
开发者ID:robertdean,项目名称:RavenMDB2,代码行数:57,代码来源:CustomUserSession.cs


注:本文中的IServiceBase.ResolveService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。