diff options
| author | mo khan <mo@mokhan.ca> | 2009-10-23 08:07:53 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2009-10-23 08:07:53 -0600 |
| commit | f76fe6ca01f3dc5fabc8bf16f299420ba9d7ef05 (patch) | |
| tree | d134ad91aa34757d5d54e05629438bf436700c69 | |
| parent | 9d86ea6db750f1e271e1311ba09491e5d4098627 (diff) | |
switched from singleton context to per thread context.
| -rw-r--r-- | product/Boot/boot/WindowsFormsApplication.cs | 45 | ||||
| -rw-r--r-- | product/Boot/boot/container/ComponentExclusionSpecificationSpecs.cs | 2 | ||||
| -rw-r--r-- | product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs | 3 | ||||
| -rw-r--r-- | product/Boot/boot/container/type_extensions.cs | 2 | ||||
| -rw-r--r-- | product/Domain/Accounting/AccountHolder.cs | 4 | ||||
| -rw-r--r-- | product/Domain/Accounting/Bill.cs | 4 | ||||
| -rw-r--r-- | product/Domain/Accounting/Company.cs | 4 | ||||
| -rw-r--r-- | product/Domain/Accounting/Income.cs | 4 | ||||
| -rw-r--r-- | product/Domain/Accounting/Payment.cs | 4 | ||||
| -rw-r--r-- | product/Domain/Core/Entity.cs | 38 | ||||
| -rw-r--r-- | product/Domain/Core/GenericEntity.cs | 41 | ||||
| -rw-r--r-- | product/Domain/Domain.csproj | 1 | ||||
| -rw-r--r-- | product/Presentation/Winforms/Views/AddBillPaymentView.cs | 3 | ||||
| -rw-r--r-- | product/database/repositories/CompanyRepository.cs | 6 |
14 files changed, 90 insertions, 71 deletions
diff --git a/product/Boot/boot/WindowsFormsApplication.cs b/product/Boot/boot/WindowsFormsApplication.cs index 64abd76..d47a5f1 100644 --- a/product/Boot/boot/WindowsFormsApplication.cs +++ b/product/Boot/boot/WindowsFormsApplication.cs @@ -29,23 +29,21 @@ namespace MoMoney.boot public void run() { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - Func<ISplashScreenPresenter> presenter = () => new SplashScreenPresenter(); - presenter = presenter.memorize(); - - var startup_screen = new display_the_splash_screen(presenter).on_a_background_thread(); + using (new LogTime()) + { + Func<ISplashScreenPresenter> presenter = () => new SplashScreenPresenter(); + presenter = presenter.memorize(); - AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); - hookup - .the<global_error_handling>() - .then(startup_screen) - .then<wire_up_the_container>() - .then(new start_the_application(startup_screen)) - .run(); + var startup_screen = new display_the_splash_screen(presenter).on_a_background_thread(); - stopwatch.Stop(); - this.log().debug("application startup took: {0}", stopwatch.Elapsed); + AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); + hookup + .the<global_error_handling>() + .then(startup_screen) + .then<wire_up_the_container>() + .then(new start_the_application(startup_screen)) + .run(); + } start(); } @@ -63,6 +61,23 @@ namespace MoMoney.boot } } + public class LogTime : IDisposable + { + Stopwatch stopwatch; + + public LogTime() + { + stopwatch = new Stopwatch(); + stopwatch.Start(); + } + + public void Dispose() + { + stopwatch.Stop(); + this.log().debug("application startup took: {0}", stopwatch.Elapsed); + } + } + public class ApplicationContainer : Container { readonly IServiceContainer container; diff --git a/product/Boot/boot/container/ComponentExclusionSpecificationSpecs.cs b/product/Boot/boot/container/ComponentExclusionSpecificationSpecs.cs index 68619d4..567aef3 100644 --- a/product/Boot/boot/container/ComponentExclusionSpecificationSpecs.cs +++ b/product/Boot/boot/container/ComponentExclusionSpecificationSpecs.cs @@ -92,7 +92,7 @@ namespace MoMoney.boot.container static public class FakeStaticClass {} - public class FakeEntity : IEntity + public class FakeEntity : Entity { public Id<Guid> id { diff --git a/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs b/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs index 3243455..b685e11 100644 --- a/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs +++ b/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs @@ -33,7 +33,8 @@ namespace MoMoney.boot.container.registration registry.transient(typeof (ITrackerEntryMapper<>), typeof (TrackerEntryMapper<>)); registry.transient(typeof (IKey<>), typeof (TypedKey<>)); registry.transient(typeof (ComponentFactory<>), typeof (DefaultConstructorFactory<>)); - registry.singleton<IContext>(() => new Context(new Hashtable())); + //registry.singleton<IContext>(() => new Context(new Hashtable())); + registry.singleton<IContext>(() => new PerThread()); registry.singleton(() => AsyncOperationManager.SynchronizationContext); registry.singleton<AsyncOperation>(() => AsyncOperationManager.CreateOperation(new object())); diff --git a/product/Boot/boot/container/type_extensions.cs b/product/Boot/boot/container/type_extensions.cs index 54a5641..4e083a7 100644 --- a/product/Boot/boot/container/type_extensions.cs +++ b/product/Boot/boot/container/type_extensions.cs @@ -25,7 +25,7 @@ namespace MoMoney.boot.container static public Specification<Type> is_an_entity(this Type item) { - return new PredicateSpecification<Type>(x => typeof (IEntity).IsAssignableFrom(x)); + return new PredicateSpecification<Type>(x => typeof (Entity).IsAssignableFrom(x)); } static public Specification<Type> is_an_interface(this Type item) diff --git a/product/Domain/Accounting/AccountHolder.cs b/product/Domain/Accounting/AccountHolder.cs index 228bfed..2b62cd5 100644 --- a/product/Domain/Accounting/AccountHolder.cs +++ b/product/Domain/Accounting/AccountHolder.cs @@ -7,7 +7,7 @@ using MoMoney.Domain.Core; namespace MoMoney.Domain.accounting { - public interface IAccountHolder : IEntity + public interface IAccountHolder : Entity { void receive(IBill bill); void receive(IIncome income); @@ -16,7 +16,7 @@ namespace MoMoney.Domain.accounting } [Serializable] - public class AccountHolder : Entity<IAccountHolder>, IAccountHolder + public class AccountHolder : GenericEntity<IAccountHolder>, IAccountHolder { IList<IBill> all_bills { get; set; } IList<IIncome> income_collected { get; set; } diff --git a/product/Domain/Accounting/Bill.cs b/product/Domain/Accounting/Bill.cs index 45f36bb..7bf4ea5 100644 --- a/product/Domain/Accounting/Bill.cs +++ b/product/Domain/Accounting/Bill.cs @@ -6,7 +6,7 @@ using gorilla.commons.utility; namespace MoMoney.Domain.Accounting { - public interface IBill : IEntity + public interface IBill : Entity { bool is_paid_for(); void pay(Money amount_to_pay); @@ -16,7 +16,7 @@ namespace MoMoney.Domain.Accounting } [Serializable] - public class Bill : Entity<IBill>, IBill + public class Bill : GenericEntity<IBill>, IBill { IList<IPayment> payments { get; set; } diff --git a/product/Domain/Accounting/Company.cs b/product/Domain/Accounting/Company.cs index 665501b..d67ad05 100644 --- a/product/Domain/Accounting/Company.cs +++ b/product/Domain/Accounting/Company.cs @@ -5,7 +5,7 @@ using MoMoney.Domain.Core; namespace MoMoney.Domain.Accounting { - public interface ICompany : IEntity + public interface ICompany : Entity { string name { get; } void change_name_to(string company_name); @@ -14,7 +14,7 @@ namespace MoMoney.Domain.Accounting } [Serializable] - public class Company : Entity<ICompany>, ICompany + public class Company : GenericEntity<ICompany>, ICompany { public string name { get; private set; } diff --git a/product/Domain/Accounting/Income.cs b/product/Domain/Accounting/Income.cs index 430134e..7b64ff3 100644 --- a/product/Domain/Accounting/Income.cs +++ b/product/Domain/Accounting/Income.cs @@ -4,7 +4,7 @@ using MoMoney.Domain.Core; namespace MoMoney.Domain.Accounting { - public interface IIncome : IEntity + public interface IIncome : Entity { Date date_of_issue { get; } Money amount_tendered { get; } @@ -12,7 +12,7 @@ namespace MoMoney.Domain.Accounting } [Serializable] - internal class Income : Entity<IIncome>, IIncome + internal class Income : GenericEntity<IIncome>, IIncome { public Income(Date date_of_issue, Money amount_tendered, ICompany company) { diff --git a/product/Domain/Accounting/Payment.cs b/product/Domain/Accounting/Payment.cs index 1c86368..00a10cd 100644 --- a/product/Domain/Accounting/Payment.cs +++ b/product/Domain/Accounting/Payment.cs @@ -3,13 +3,13 @@ using MoMoney.Domain.Core; namespace MoMoney.Domain.Accounting { - public interface IPayment : IEntity + public interface IPayment : Entity { Money apply_to(Money money); } [Serializable] - internal class Payment : Entity<IPayment>, IPayment + internal class Payment : GenericEntity<IPayment>, IPayment { Money amount_paid { get; set; } diff --git a/product/Domain/Core/Entity.cs b/product/Domain/Core/Entity.cs index 5183e48..4bf8324 100644 --- a/product/Domain/Core/Entity.cs +++ b/product/Domain/Core/Entity.cs @@ -3,41 +3,5 @@ using gorilla.commons.utility; namespace MoMoney.Domain.Core { - public interface IEntity : Identifiable<Guid> {} - - [Serializable] - public abstract class Entity<T> : IEntity where T : class, IEntity - { - protected Entity() - { - id = Guid.NewGuid(); - } - - public Id<Guid> id { get; private set; } - - public bool Equals(Entity<T> obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.id.Equals(id); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != typeof (Entity<T>)) return false; - return Equals((Entity<T>) obj); - } - - public override int GetHashCode() - { - return id.GetHashCode(); - } - - public override string ToString() - { - return "{0} id: {1}".formatted_using(base.ToString(), id); - } - } + public interface Entity : Identifiable<Guid> {} }
\ No newline at end of file diff --git a/product/Domain/Core/GenericEntity.cs b/product/Domain/Core/GenericEntity.cs new file mode 100644 index 0000000..01fdf9d --- /dev/null +++ b/product/Domain/Core/GenericEntity.cs @@ -0,0 +1,41 @@ +using System; +using gorilla.commons.utility; + +namespace MoMoney.Domain.Core +{ + [Serializable] + public abstract class GenericEntity<T> : Entity where T : class, Entity + { + protected GenericEntity() + { + id = Guid.NewGuid(); + } + + public Id<Guid> id { get; private set; } + + public bool Equals(GenericEntity<T> obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.id.Equals(id); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (GenericEntity<T>)) return false; + return Equals((GenericEntity<T>) obj); + } + + public override int GetHashCode() + { + return id.GetHashCode(); + } + + public override string ToString() + { + return "{0} id: {1}".formatted_using(base.ToString(), id); + } + } +}
\ No newline at end of file diff --git a/product/Domain/Domain.csproj b/product/Domain/Domain.csproj index fef13a2..ff1e67e 100644 --- a/product/Domain/Domain.csproj +++ b/product/Domain/Domain.csproj @@ -80,6 +80,7 @@ <Compile Include="accounting\GeneralLedgerSpecs.cs" /> <Compile Include="accounting\AnnualIncomeVisitor.cs" /> <Compile Include="accounting\IncomeExtensions.cs" /> + <Compile Include="core\GenericEntity.cs" /> <Compile Include="core\Entity.cs" /> <Compile Include="core\Money.cs" /> <Compile Include="core\MoneyExtensions.cs" /> diff --git a/product/Presentation/Winforms/Views/AddBillPaymentView.cs b/product/Presentation/Winforms/Views/AddBillPaymentView.cs index 06a4dc5..1c48fd1 100644 --- a/product/Presentation/Winforms/Views/AddBillPaymentView.cs +++ b/product/Presentation/Winforms/Views/AddBillPaymentView.cs @@ -18,8 +18,7 @@ namespace MoMoney.Presentation.Winforms.Views public AddBillPaymentView() { InitializeComponent(); - titled("Add Bill Payment") - .icon(ApplicationIcons.AddBillPayment); + titled("Add Bill Payment").icon(ApplicationIcons.AddBillPayment); ux_submit_button.Click += (sender, e) => submit_clicked(e); companies_list = ux_company_names.create_for<CompanyDTO>(); } diff --git a/product/database/repositories/CompanyRepository.cs b/product/database/repositories/CompanyRepository.cs index b009cc7..7f34e3e 100644 --- a/product/database/repositories/CompanyRepository.cs +++ b/product/database/repositories/CompanyRepository.cs @@ -24,14 +24,12 @@ namespace momoney.database.repositories public ICompany find_company_named(string name) { - return session - .all<ICompany>() - .SingleOrDefault(x => x.name.is_equal_to_ignoring_case(name)); + return all().SingleOrDefault(x => x.name.is_equal_to_ignoring_case(name)); } public ICompany find_company_by(Guid id) { - return session.all<ICompany>().SingleOrDefault(x => x.id.Equals(id)); + return all().SingleOrDefault(x => x.id.Equals(id)); } public void save(ICompany company) |
