Skip to content

Instantly share code, notes, and snippets.

View bsommardahl's full-sized avatar

Byron Sommardahl bsommardahl

View GitHub Profile
@bsommardahl
bsommardahl / gist:3387787
Created August 18, 2012 15:38
Anemic CustomerAddress
public class CustomerAddress
{
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
@bsommardahl
bsommardahl / gist:3387814
Created August 18, 2012 15:43
Auto-updating Entity
public class CustomerAddress
{
public event DomainEvent NotifyObservers;
string _name;
public string Name
{
get { return _name; }
set
{
@bsommardahl
bsommardahl / gist:3387866
Created August 18, 2012 15:50
Address changed handler
public class UpdateCustomerAddressAfterChange : IDomainEventHandler<CustomerAddressChanged>
{
readonly IRepository _repository;
public UpdateCustomerAddressAfterChange(IRepository repository)
{
_repository = repository;
}
public void Handle(CustomerAddressChanged @event)
@bsommardahl
bsommardahl / gist:3387958
Created August 18, 2012 15:57
Complete Auto-Updating CustomerAddress Entity
public class CustomerAddress
{
public event DomainEvent NotifyObservers;
string _name;
public string Name
{
get { return _name; }
set
{
var customer = _repository.Get<Customer>(6543);
customer.CustomerAddress.Name = "some new name";
//event processed to update this CustomerAddress instance
@bsommardahl
bsommardahl / gist:3492053
Created August 27, 2012 20:41
BlingInterceptor
public class BlingInterceptor : EmptyInterceptor
{
readonly IBlingInitializer _blingInitializer;
public BlingInterceptor(IBlingInitializer blingInitializer)
{
_blingInitializer = blingInitializer;
}
public override bool OnLoad(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
public interface IObjectPropertyChangerActor<out T>
{
IObjectPropertyChangerActor<T> With(Action<T> action);
IObjectPropertyChangerActor<T> And(Action<T> action);
}
public class ObjectPropertyChangerActor<T> : IObjectPropertyChangerActor<T>
{
readonly T _objectToChange;
public class Car
{
public string Color { get; set; }
public string Model { get; set; }
public string Make { get; set; }
public string Year { get; set; }
}
public class given_an_object_property_changer_context
{
public class BusinessDayCalculator : IBusinessDayCalculator
{
private readonly IHolidayProvider _holidayProvider;
public BusinessDayCalculator(IHolidayProvider holidayProvider)
{
_holidayProvider = holidayProvider;
}
public DateTime AddBusinessDays(DateTime startDate, int businessDays)
public Monkey GetMonkeyById(int id)
{
var monkey = _monkeyRepository.Get(id);
return monkey;
}