Skip to content

Commit

Permalink
Integration of CommonDomain by Jonathan Oliver
Browse files Browse the repository at this point in the history
  • Loading branch information
JoergEg committed Mar 2, 2011
1 parent 5cec9f9 commit 227a30f
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 290 deletions.
12 changes: 8 additions & 4 deletions CQRSSample.App/CQRSSample.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\Castle Windsor\dotNet40\Castle.Windsor.dll</HintPath>
</Reference>
<Reference Include="CommonDomain">
<HintPath>..\External Libs\CommonDomain\bin\CommonDomain.dll</HintPath>
</Reference>
<Reference Include="EventStore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7735eb81c0bd9948, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\EventStore\bin\EventStore.dll</HintPath>
<HintPath>..\External Libs\CommonDomain\bin\EventStore.dll</HintPath>
</Reference>
<Reference Include="EventStore.Persistence.RavenPersistence, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7735eb81c0bd9948, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\EventStore\bin\EventStore.Persistence.RavenPersistence.dll</HintPath>
<HintPath>..\External Libs\CommonDomain\bin\EventStore.Persistence.RavenPersistence.dll</HintPath>
</Reference>
<Reference Include="EventStore.Serialization.Json">
<HintPath>..\External Libs\EventStore\bin\EventStore.Serialization.Json.dll</HintPath>
<Reference Include="EventStore.Serialization.Json, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7735eb81c0bd9948, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\CommonDomain\bin\EventStore.Serialization.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
Expand Down
4 changes: 3 additions & 1 deletion CQRSSample.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ class Program
static void Main()
{
var store = new DocumentStore{ Url = "http://localhost:8080" };
store.Initialize();

//run RavenDB InMemory
//var store = new EmbeddableDocumentStore {RunInMemory = true};

IWindsorContainer container = null;
try
{
container = BootStrapper.BootStrap(store);
container = BootStrapper.BootStrap();

var bus = container.Resolve<IBus>();
var aggregateId = Guid.NewGuid();
Expand Down
20 changes: 10 additions & 10 deletions CQRSSample/CQRSSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\Castle Windsor\dotNet40\Castle.Windsor.dll</HintPath>
</Reference>
<Reference Include="CommonDomain">
<HintPath>..\External Libs\CommonDomain\bin\CommonDomain.dll</HintPath>
</Reference>
<Reference Include="EventStore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7735eb81c0bd9948, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\EventStore\bin\EventStore.dll</HintPath>
<HintPath>..\External Libs\CommonDomain\bin\EventStore.dll</HintPath>
</Reference>
<Reference Include="EventStore.Persistence.RavenPersistence, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7735eb81c0bd9948, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\EventStore\bin\EventStore.Persistence.RavenPersistence.dll</HintPath>
<HintPath>..\External Libs\CommonDomain\bin\EventStore.Persistence.RavenPersistence.dll</HintPath>
</Reference>
<Reference Include="EventStore.Serialization.Json">
<HintPath>..\External Libs\EventStore\bin\EventStore.Serialization.Json.dll</HintPath>
<Reference Include="EventStore.Serialization.Json, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7735eb81c0bd9948, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libs\CommonDomain\bin\EventStore.Serialization.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand All @@ -67,7 +71,6 @@
<Reference Include="System.Data.DataSetExtensions" />
</ItemGroup>
<ItemGroup>
<Compile Include="Domain\AggregateRoot.cs" />
<Compile Include="Events\DomainEvent.cs" />
<Compile Include="Commands\Command.cs" />
<Compile Include="Commands\RelocatingCustomerCommand.cs" />
Expand All @@ -80,19 +83,16 @@
<Compile Include="CommandHandlers\TransactionHandler.cs" />
<Compile Include="Commands\CreateCustomerCommand.cs" />
<Compile Include="Domain\Customer.cs" />
<Compile Include="Domain\IAggregateRoot.cs" />
<Compile Include="Domain\IEventStore.cs" />
<Compile Include="Domain\IRepository.cs" />
<Compile Include="Events\CustomerCreatedEvent.cs" />
<Compile Include="Infrastructure\AggregateFactory.cs" />
<Compile Include="Infrastructure\BootStrapper.cs" />
<Compile Include="Infrastructure\DelegateAdjuster.cs" />
<Compile Include="Infrastructure\EventDescriptor.cs" />
<Compile Include="Infrastructure\FakeBus.cs" />
<Compile Include="Infrastructure\InProcessBus.cs" />
<Compile Include="Infrastructure\Installers\AllTypesWithAllInterfaceInstaller.cs" />
<Compile Include="Infrastructure\Installers\EventHandlerHelper.cs" />
<Compile Include="Infrastructure\Installers\EventStoreInstaller.cs" />
<Compile Include="Infrastructure\RavenDbEventStore.cs" />
<Compile Include="Infrastructure\RavenInMemoryPersistenceFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
Expand Down
7 changes: 4 additions & 3 deletions CQRSSample/CommandHandlers/CustomerCommandHandlers.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using CQRSSample.Commands;
using CQRSSample.Domain;
using CommonDomain.Persistence;

namespace CQRSSample.CommandHandlers
{
public class RelocatingCustomerCommandHandler : Handles<RelocatingCustomerCommand>
{
private readonly IRepository<Customer> _repository;
private readonly IRepository _repository;

public RelocatingCustomerCommandHandler(IRepository<Customer> repository)
public RelocatingCustomerCommandHandler(IRepository repository)
{
_repository = repository;
}

public void Handle(RelocatingCustomerCommand command)
{
var customer = _repository.GetById(command.Id);
var customer = _repository.GetById<Customer>(command.Id, command.Version);
customer.RelocateCustomer(command.Street, command.Streetnumber, command.PostalCode, command.City);
_repository.Save(customer, customer.Version);
}
Expand Down
58 changes: 0 additions & 58 deletions CQRSSample/Domain/AggregateRoot.cs

This file was deleted.

17 changes: 6 additions & 11 deletions CQRSSample/Domain/Customer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using CommonDomain.Core;
using CQRSSample.Events;

namespace CQRSSample.Domain
{
public class Customer : AggregateRoot
public class Customer : AggregateBase<DomainEvent>
{
private bool _deactivated;
private CustomerName _customerName;
Expand All @@ -12,25 +13,19 @@ public class Customer : AggregateRoot

private Customer(Guid id, CustomerName customerName, Address address, PhoneNumber phoneNumber)
{
ApplyChange(new CustomerCreatedEvent(id, customerName.Name, address.Street, address.StreetNumber, address.PostalCode, address.City, phoneNumber.Number));
RaiseEvent(new CustomerCreatedEvent(id, customerName.Name, address.Street, address.StreetNumber, address.PostalCode, address.City, phoneNumber.Number));
}

public Customer()
{
}

private Guid _id;
public override Guid Id
{
get { return _id; }
}


public void RelocateCustomer(string street, string streetNumber, string postalCode, string city)
{
if (Id == Guid.Empty)
throw new NonExistingCustomerException("The customer is not created and no opperations can be executed on it");

ApplyChange(new CustomerRelocatedEvent(Id, street, streetNumber, postalCode, city));
RaiseEvent(new CustomerRelocatedEvent(Id, street, streetNumber, postalCode, city));
}

public static Customer CreateNew(Guid id, CustomerName customerName, Address address, PhoneNumber phoneNumber)
Expand All @@ -43,7 +38,7 @@ public static Customer CreateNew(Guid id, CustomerName customerName, Address add
//Domain-Eventhandlers
private void Apply(CustomerCreatedEvent @event)
{
_id = @event.AggregateId;
Id = @event.AggregateId;
_customerName = new CustomerName(@event.CustomerName);
_address = new Address(@event.Street, @event.StreetNumber, @event.PostalCode, @event.City);
_phoneNumber = new PhoneNumber(@event.PhoneNumber);
Expand Down
11 changes: 0 additions & 11 deletions CQRSSample/Domain/IAggregateRoot.cs

This file was deleted.

12 changes: 0 additions & 12 deletions CQRSSample/Domain/IEventStore.cs

This file was deleted.

73 changes: 0 additions & 73 deletions CQRSSample/Domain/IRepository.cs

This file was deleted.

6 changes: 2 additions & 4 deletions CQRSSample/Infrastructure/BootStrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ namespace CQRSSample.Infrastructure
{
public class BootStrapper
{
public static IWindsorContainer BootStrap(IDocumentStore store)
public static IWindsorContainer BootStrap()
{
store.Initialize();

var container = new WindsorContainer();

container.Register(Component.For<IDocumentStore>().Instance(store));
//container.Register(Component.For<IDocumentStore>().Instance(store));
container.Register(Component.For<IWindsorContainer>().Instance(container));

// adds and configures all components using WindsorInstallers from executing assembly
Expand Down
Loading

0 comments on commit 227a30f

Please sign in to comment.