Here is what my controllers tend to look like, its not complete but I would love to see how others do it. -dru
[Rescue("error")] public class BookController : BaseController { //ARSessionModule in effect so we don't have to manage the session //The method is marked virtual so we can intercept it and add things like logging //The class has a Rescue attribute so we don't have to manage error screens private Repository<Book> _repository; public BookController(Repository<Book> repository) { this._repository = repository; } public virtual void View(Guid id) { this.PropertyBag.Add("book", this._repository.Load(id)); } public virtual void Delete(Guid id) { this._repository.Delete(id); } }
This is indicative of how mine look at the moment:
public partial class EditBookController : BookControllerBase<IEditBookView> { private IBookRepository bookRepository; public EditBookController(ICodeGeneratorServices codeGeneratorServices, IDictionaryAdapterFactory dictionaryAdapterFactory, IBookRepository bookRepository) : base(codeGeneratorServices, dictionaryAdapterFactory) { this.bookRepository = bookRepository; } [AccessibleThrough(Verb.Post)] public void Process([Databind("book")] Book book) { bookRepository.Update(book); TypedFlash.SuccessMessage = "Updated successfully"; Site.Books.Actions.EditBook.Display(book.Id).Redirect; } public void Display(int id) { TypedPropertyBag.Book = bookRepository.Load(id); TypedPropertyBag.UserName = TypedSession.UserName; if (TypedPropertyBag.Book.Type == BookType.Paperback) MyViews.Paperback.Render(); else MyViews.Hardback.Render(); } }
I'm using the SiteMap and DictionaryAdapterFactory from the Castle.Tools.CodeGenerator to strongly-type my use of the PropetyBag, Flash and Session and redirections. -lee
