Ejemplo n.º 1
0
 public IQuery <T> GetHandler <T>(Criteria criteria = null)
 {
     criteria = criteria ?? new Criteria();
     RunInterceptor <T>(criteria);
     if (QueryHandlers.ContainsKey(typeof(T)))
     {
         return(QueryHandlers[typeof(T)] as IQuery <T>);
     }
     return(null);
 }
Ejemplo n.º 2
0
 public Dictionary <string, List <KeyValuePair <string, string> > > GetFilterTypes <T>(IList <T> results, Criteria criteria)
 {
     if (QueryHandlers.ContainsKey(typeof(T)))
     {
         var handler = QueryHandlers[typeof(T)] as IQuery <T>;
         if (handler != null)
         {
             var types = handler.GetFilterTypes(results, criteria);
             return(types);
         }
     }
     return(new Dictionary <string, List <KeyValuePair <string, string> > >());
 }
Ejemplo n.º 3
0
        static void bootstrap()
        {
            var getUser = new Func <int, User>(id => User.FromMemento(Query.Get <UserMemento>(new ById(id))));

            // Commands
            Commands.Register <CreateUser>(createUser =>
                                           LogHandlers <CreateUser> .Log(createUser,
                                                                         () => CommandHandlers.CreateUser(createUser)));

            Commands.Register <UpdateProfile>(updateProfile =>
                                              LogHandlers <UpdateProfile> .Log(updateProfile,
                                                                               () => CommandHandlers.UpdateProfile(updateProfile, getUser(updateProfile.ID))));

            Commands.Register <AddFriend>(addFriend =>
                                          LogHandlers <AddFriend> .Log(addFriend,
                                                                       () => CommandHandlers.AddFriend(addFriend, getUser(addFriend.ID))));


            // Queries
            Query.Register <List <UserProfile>, All>(all =>
                                                     wrapWithDatabase(db => QueryHandlers.GetAllProfiles(db)));

            Query.Register <List <Friend>, ByUserId>(byUserId =>
                                                     wrapWithDatabase(db => QueryHandlers.GetFriends(byUserId.UserId, db)));

            Query.Register <UserMemento, ById>(byId =>
                                               wrapWithDatabase(db => QueryHandlers.GetuserMemento(byId.ID, db)));

            // Events
            Events.Register <ProfileUpdated>(profileUpdated =>
                                             wrapWithDatabase(db => EventHandlers.ProfileUpdated(profileUpdated, db)));

            Events.Register <UserCreated>(userCreated =>
                                          wrapWithDatabase(db => EventHandlers.UserCreated(userCreated, db)));

            Events.Register <FriendAdded>(friendAdded =>
                                          wrapWithDatabase(db => EventHandlers.FriendAdded(friendAdded, db)));
        }