Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created December 11, 2009 15:27
Show Gist options
  • Save mxriverlynn/254270 to your computer and use it in GitHub Desktop.
Save mxriverlynn/254270 to your computer and use it in GitHub Desktop.
public class AppController: IApplicationController
{
//other app controller stuff here
public R Query<T,R>(T queryData)
{
R returnValue = default(R);
IQuery<T,R> query = iocContainer.GetInstance<IQuery<T,R>>();
if (query != null)
returnValue = query.Query(T);
return returnValue;
}
//other app controller stuff here
}
public class DisplayUsersPresenter.cs
{
private IApplicationController AppController{ get; set; }
private IDisplayUsersView View{ get; set; }
public SomeService(IDisplayUsersView view, IApplicationController appController)
{
View = view;
AppController = appController;
}
public void GetAllUsers()
{
IList<User> users = AppController.Query<GetAllUsers, IList<User>>();
View.ShowUsers(users);
}
}
public class GetAllUsers
{
//empty class used as a marker to determine what query object should be executed
}
public interface IQuery<T,R>
{
R Query(T queryData);
}
public class MyRepository: IQuery<GetAllUsers, IList<User>>
{
public IList<User> Query(GetAllUsers queryData)
{
IList<User> users = //retrieve all users from the database, here.;
return users;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment