Skip to content

Instantly share code, notes, and snippets.

View jmarnold's full-sized avatar

Josh Arnold jmarnold

View GitHub Profile
@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 / 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 / ISpecification.cs
Created May 17, 2011 03:30
Specifications
public interface ISpecification<T>
{
Expression<Func<T, bool>> IsSatisfied();
}
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;
// 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 interface IPartialDecorator<T>
where T : class
{
T Enrich(T target);
}
public void Invoke()
{
if (performInvoke() == DoNext.Continue && InsideBehavior != null)
{
InsideBehavior.Invoke();
}
afterInsideBehavior();
}
@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;
[Test]
public void should_return_single_view_token_matched_on_policy_criteria()
{
_descriptor.Templates.Add("Projects\\Dashboard.spark");
_descriptor.Templates.Add("Shared\\Application.spark");
var descriptor2 = newDescriptor();
descriptor2.Templates.Add("Projects\\StoryMap.spark");
descriptor2.Templates.Add("Shared\\Application.spark");
_token.Descriptors.Add(descriptor2);
public class OrderProcessingModule
{
public void Process(OrderStatusMessage orderStatusMessage)
{
string connectionString = ConfigurationManager.ConnectionStrings["Main"].ConnectionString;
Order order = null;
using(var connection = new SqlConnection(connectionString))
{
order = FetchData(orderStatusMessage, connection);