Created
January 26, 2011 02:23
-
-
Save randomcodenz/796115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Implementation of this basically looks up the appropriate command handler from a container | |
// and calls Handle passing the command | |
public interface ICommandExecutor | |
{ | |
Guid ExecuteCreate<T>( T createCommand ); | |
void Execute<T>( T command ); | |
} | |
public interface ICommandHandler<T> | |
{ | |
void Handle( T command ); | |
} | |
public interface ICreateCommandHandler<T> | |
{ | |
Guid Handle( T createCommand ); | |
} | |
public class CreateSomethingCommandHandler : ICommandHandler<CreateSomethingCommand> | |
{ | |
public void Handle( CreateSomethingCommand command ) | |
{ | |
var something = new Something( ... ); | |
// Do other bits required like add to repository | |
// Now we have something.Id but how to get it back to the caller??? | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Implementation basically looks up the appropriate view factory from a container and calls Load passing the input if any | |
public interface IViewRepository | |
{ | |
TView Load<TView>(); | |
TView Load<TInput,TView>( TInput input ); | |
} | |
public interface IViewFactory<TView> | |
{ | |
TView Load(); | |
} | |
public interface IViewFactory<TInput,TView> | |
{ | |
TView Load(TInput input); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SomeController : Controller | |
{ | |
private readonly IViewRepository _views; | |
private readonly ICommandExecutor _commandExecutor; | |
public ActionResult DoSomething( SomeNewForm theForm ) | |
{ | |
if( !Model.IsValid ) | |
{ | |
return View(); | |
} | |
_commandExecutor.Execute( new CreateSomethingCommand( theForm.Name ) ); | |
return RedirectToAction( "ShowSomething", new {Id = ???} ) // ***** where to get the id from? *** | |
} | |
public ActionResult ShowSomething( SomeUrl url ) | |
{ | |
var somethingView = _views.Load<SomeUrl,ShowSomethingView>( url ); | |
if( view == null ) | |
{ | |
return View( "SomethingNotFound" ); | |
} | |
return View( somethingView ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment