Skip to content

Instantly share code, notes, and snippets.

@rauhryan
Created October 20, 2011 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauhryan/1302008 to your computer and use it in GitHub Desktop.
Save rauhryan/1302008 to your computer and use it in GitHub Desktop.
//////////////////Behavior
public class TransactionalContainerBehavior : IActionBehavior
{
private readonly IContainer _container;
private readonly ServiceArguments _arguments;
private readonly Guid _behaviorId;
public TransactionalContainerBehavior(IContainer container, ServiceArguments arguments, Guid behaviorId)
{
_container = container;
_arguments = arguments;
_behaviorId = behaviorId;
}
public void Invoke()
{
var token = _container.GetInstance<IFubuRequest>().Get<TokenRequest>();
/// what is token.Token?
InvokeRequestedBehavior(c);
}
public void InvokePartial(){}
private void InvokeRequestedBehavior(IContainer c)
{
var behavior = c.GetInstance<IActionBehavior>(_arguments.ToExplicitArgs(), _behaviorId.ToString());
behavior.Invoke();
}
}
////////////////// Model Bound Class
public class TokenRequest
{
public string Token {get; set; }
}
////////////////// Facility
public class RestAPIContainerFacility : StructureMapContainerFacility
{
private readonly IContainer _container;
public RestAPIContainerFacility(IContainer container)
: base(container)
{
_container = container;
}
public override FubuMVC.Core.Behaviors.IActionBehavior BuildBehavior(FubuCore.Binding.ServiceArguments arguments, Guid behaviorId)
{
return new TransactionalContainerBehavior(_container, arguments, behaviorId);
}
}
/////////////////////// USAGE
FubuApplication
.For<RestApiFubuRegistry>()
.ContainerFacility(new RestAPIContainerFacility(ObjectFactory.Container))
.Bootstrap(RouteTable.Routes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment