Skip to content

Instantly share code, notes, and snippets.

View jmarnold's full-sized avatar

Josh Arnold jmarnold

View GitHub Profile
@jmarnold
jmarnold / IValidationQuery.cs
Created January 24, 2011 02:50
Validation Rules in Fubu
public interface IValidationQuery
{
IEnumerable<IValidationRule> RulesFor(object target);
IEnumerable<IValidationRule> RulesFor(Type targetType);
T GetRule<T>(Accessor accessor) where T : class, IValidationRule;
T GetStrategy<T>(Accessor accessor) where T : class, IFieldValidationStrategy;
void ForRule<T>(Accessor accessor, Action<T, Accessor> action) where T : class, IValidationRule;
void ForStrategy<T>(Accessor accessor, Action<T, Accessor> action) where T : class, IFieldValidationStrategy;
bool HasRule<T>(Accessor accessor) where T : class, IValidationRule;
bool HasStrategy<T>(Accessor accessor) where T : class, IFieldValidationStrategy;
public void Invoke()
{
if (performInvoke() == DoNext.Continue && InsideBehavior != null)
{
InsideBehavior.Invoke();
}
afterInsideBehavior();
}
public interface IPartialDecorator<T>
where T : class
{
T Enrich(T target);
}
// TODO -- come back and clean this up. Just getting it up and running for a demo
BehaviorDetailsModel root = null;
var behaviors = new Cache<Type, BehaviorDetailsModel>(t =>
{
var model = new BehaviorDetailsModel {BehaviorType = t};
if(root == null)
{
root = model;
}
public class RequiresAuthenticationConvention : IConfigurationAction
{
public void Configure(BehaviorGraph graph)
{
graph
.Actions()
.Where(action => action.HasInput && !action.InputType().HasAttribute<AllowUnauthenticatedAccessAttribute>())
.Each(call =>
{
var log = graph.Observer;
@jmarnold
jmarnold / ISpecification.cs
Created May 17, 2011 03:30
Specifications
public interface ISpecification<T>
{
Expression<Func<T, bool>> IsSatisfied();
}
@jmarnold
jmarnold / BaseRepository.cs
Created May 27, 2011 15:40
Specifications, Policies, and Composition
public virtual IQueryable<T> Query(ISpecification<T> query)
{
var specifications = new List<ISpecification<T>>();
_specificationPolicies
.Where(p => p.Applies<T>())
.Select(p => p.Build<T>())
.Each(specifications.Add);
_entityPolicies
@jmarnold
jmarnold / ApplicationSetting.cs
Created June 6, 2011 14:53
Configurable Configuration
public class ApplicationSetting : ISiteContextualEntity
{
public string Key { get; set; }
public string Value { get; set; }
public int SiteId { get; set; }
public Site Site { get; set; }
}
@jmarnold
jmarnold / jbus-example.js
Created June 17, 2011 21:56
Example bootstrapping
jBus.routing.initialize(function() {
this.connectTo('ws://jmarnold-logist:8181');
this.on('TimestampCaseCommand', function(msg) {
$('#Case1').find('.checkpoint-' + msg.Checkpoint).html(msg.Value);
});
this.on('PulseCommand', function(msg) {
$('#Pulse').html(msg.Message);
});
});
@jmarnold
jmarnold / SampleDashboardModel.cs
Created June 23, 2011 19:05
Sample Dashboard
public class SampleDashboardModel
{
public IEnumerable<IDashboardWidget> Widgets { get; set;
}