Skip to content

Instantly share code, notes, and snippets.

@udidahan
Created March 4, 2011 12:03
Show Gist options
  • Save udidahan/854518 to your computer and use it in GitHub Desktop.
Save udidahan/854518 to your computer and use it in GitHub Desktop.
Udi Dahan ADSD refactoring
public class CC1 : IHandleMessages<MakeCustomerPreferred>
{
public IBus Bus { get; set; }
public void Handle(MakeCustomerPreferred message)
{
Bus.Publish<CustomerHasBeenMadePreferred>(m => m.CustomerId = message.CustomerId);
}
}
public class BillingSagaData : IContainSagaData
{
public Guid Id { get; set; }
public string Originator { get; set; }
public string OriginalMessageId { get; set; }
public bool IsPreferred { get; set; }
public Guid CustomerId { get; set; }
}
public class BillingSaga : NServiceBus.Saga.Saga<BillingSagaData>,
IAmStartedByMessages<OrderAccepted>,
IAmStartedByMessages<CustomerHasBeenMadePreferred>
{
public override void ConfigureHowToFindSaga()
{
ConfigureMapping<OrderAccepted>(s => s.CustomerId, m => m.CustomerId);
}
public void Handle(CustomerHasBeenMadePreferred message)
{
Data.IsPreferred = true;
Data.CustomerId = message.CustomerId;
}
public void Handle(OrderAccepted message)
{
Data.CustomerId = message.CustomerId;
if (Data.IsPreferred)
Bus.Send<DiscountOrderBecauseCustomerBecamePreferred>(m => m.OrderId = message.OrderId);
else
RequestTimeout(TimeSpan.FromHours(1), message.OrderId);
}
public override void Timeout(object state)
{
if (Data.IsPreferred)
Bus.Send<DiscountOrderBecauseCustomerBecamePreferred>(m => m.OrderId = message.OrderId);
}
}
public class B2: IHandleMessages<DiscountOrderBecauseCustomerBecamePreferred>
{
public void Handle(DiscountOrderBecauseCustomerBecamePreferred message)
{
var o = ORM.Get<Order>(message.OrderId);
o.Discount(10.Percent);
}
}
public class MakeCustomerPreferred : IMessage
{
public Guid CustomerId { get; set; }
}
public interface CustomerHasBeenMadePreferred : IMessage
{
Guid CustomerId { get; set; }
}
public class DiscountOrderBecauseCustomerBecamePreferred : IMessage
{
public Guid OrderId { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment