├── .gitattributes ├── .gitignore ├── AppInfraDemo ├── .Exercises │ ├── PointsOfAttention.html │ ├── PointsOfAttention.md │ ├── readme.html │ └── readme.md ├── .editorconfig ├── ClassDiagram.png ├── DemoApplication.sln ├── Infrastructure │ ├── CodeMap.dgml │ ├── Common │ │ ├── App.config │ │ ├── Common.csproj │ │ ├── DataModel │ │ │ ├── Abstractions │ │ │ │ └── Demo_IAuditable.cs │ │ │ └── Demo_AuditableInterceptor.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ ├── DataAccess │ │ ├── App.config │ │ ├── CollectionExtensions.cs │ │ ├── DataAccess.csproj │ │ ├── DbContexts │ │ │ ├── SalesEntities.Context.cs │ │ │ └── SalesEntities.Context.tt │ │ ├── EfRepository.cs │ │ ├── EntityEntry.cs │ │ ├── EntityInterceptor.cs │ │ ├── Exceptions │ │ │ ├── ConcurrencyRepositoryException.cs │ │ │ ├── DataValidationException.cs │ │ │ ├── DataValidationResult.cs │ │ │ ├── DateTimeRangeRepositoryException.cs │ │ │ ├── DeadlockVictimRepositoryException.cs │ │ │ ├── DeleteConstraintRepositoryException.cs │ │ │ ├── Handlers │ │ │ │ ├── ConcurrencyExceptionHandler.cs │ │ │ │ ├── DbEntityValidationExceptionHandler.cs │ │ │ │ ├── DefaultExceptionHandler.cs │ │ │ │ ├── ExceptionHandler.cs │ │ │ │ ├── IExceptionHandler.cs │ │ │ │ ├── SqlExceptionHandler.cs │ │ │ │ └── UpdateExceptionHandler.cs │ │ │ ├── RepositoryException.cd │ │ │ ├── RepositoryException.cs │ │ │ ├── RepositoryUpdateException.cs │ │ │ ├── UniqueConstraintRepositoryException.cs │ │ │ └── ValidationError.cs │ │ ├── GlobalEntityInterceptor.cs │ │ ├── IDbContextFactory.cs │ │ ├── IEntityEntryFacade.cs │ │ ├── IEntityInterceptor.cs │ │ ├── IRepository.cs │ │ ├── IUnitOfWork.cs │ │ ├── InterceptorsResolver.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── RepositoryDiagram.cd │ │ ├── SimplifiedIsolationLevel.cs │ │ └── packages.config │ └── DependencyValidation │ │ ├── DependencyValidation.layerdiagram │ │ ├── DependencyValidation.layerdiagram.layout │ │ ├── DependencyValidation.layerdiagram.suppressions │ │ └── DependencyValidation.modelproj ├── Modules │ ├── Contracts │ │ ├── Contracts.csproj │ │ ├── Crm │ │ │ └── ICrmService.cs │ │ ├── Location │ │ │ └── ILocationService.cs │ │ ├── Notifications │ │ │ ├── IAmAliveSubscriber.cs │ │ │ ├── INotificationService.cs │ │ │ ├── IStateChangeSubscriber.cs │ │ │ └── Status.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── Sales │ │ │ ├── IOrderingService.cs │ │ │ ├── OrderRequest.cs │ │ │ ├── SalesOrderInfo.cs │ │ │ └── SalesOrderResult.cs │ │ └── packages.config │ ├── DataModel │ │ ├── Customer.cs │ │ ├── DataModel.csproj │ │ ├── Order.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ ├── Export │ │ ├── Export.DataModel │ │ │ ├── App.Config │ │ │ ├── Category.cs │ │ │ ├── Customer.cs │ │ │ ├── CustomerDemographic.cs │ │ │ ├── Employee.cs │ │ │ ├── Export.DataModel.csproj │ │ │ ├── ExportEntities.Designer.cs │ │ │ ├── ExportEntities.cs │ │ │ ├── ExportEntities.edmx │ │ │ ├── ExportEntities.edmx.diagram │ │ │ ├── ExportEntities.tt │ │ │ ├── Order.cs │ │ │ ├── Order_Detail.cs │ │ │ ├── Product.cs │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── Region.cs │ │ │ ├── Shipper.cs │ │ │ ├── Supplier.cs │ │ │ ├── Territory.cs │ │ │ └── packages.config │ │ └── Export.Services │ │ │ ├── Export.Services.csproj │ │ │ ├── PageXmlDemo │ │ │ ├── CustomerData.cs │ │ │ ├── PageContentEnricher.cs │ │ │ ├── PageData.cs │ │ │ ├── PageXml.cs │ │ │ └── PageXmlExport.cs │ │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ │ ├── app.config │ │ │ └── packages.config │ ├── Notifications │ │ └── Notification.Services │ │ │ ├── NotificationService.cs │ │ │ ├── Notifications.Services.csproj │ │ │ ├── OrderStateChangeSubscriber.cs │ │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ │ ├── StateChangeSubscriber.cs │ │ │ ├── app.config │ │ │ └── packages.config │ └── Sales │ │ ├── Sales.DataAccess │ │ ├── App.config │ │ ├── DbContextFactory.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── Sales.DataAccess.csproj │ │ ├── SalesEntities.Context.Context.cs │ │ ├── SalesEntities.Context.Context.tt │ │ └── packages.config │ │ ├── Sales.DataModel │ │ ├── App.Config │ │ ├── CountryRegionCurrency.cs │ │ ├── CreditCard.cs │ │ ├── Currency.cs │ │ ├── CurrencyRate.cs │ │ ├── Customer.cs │ │ ├── Person.cs │ │ ├── PersonCreditCard.cs │ │ ├── Product.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── Sales.DataModel.csproj │ │ ├── SalesEntities.Designer.cs │ │ ├── SalesEntities.cs │ │ ├── SalesEntities.edmx │ │ ├── SalesEntities.edmx.diagram │ │ ├── SalesEntities.tt │ │ ├── SalesOrderDetail.cs │ │ ├── SalesOrderHeader.cs │ │ ├── SalesOrderHeaderSalesReason.cs │ │ ├── SalesPerson.cs │ │ ├── SalesPersonQuotaHistory.cs │ │ ├── SalesReason.cs │ │ ├── SalesTaxRate.cs │ │ ├── SalesTerritory.cs │ │ ├── SalesTerritoryHistory.cs │ │ ├── ShoppingCartItem.cs │ │ ├── SpecialOffer.cs │ │ ├── SpecialOfferProduct.cs │ │ ├── Store.cs │ │ ├── Values │ │ │ └── SalesOrderHeaderStatusValues.cs │ │ └── packages.config │ │ └── Sales.Services │ │ ├── ApprovalService.cs │ │ ├── IApprovalService.cs │ │ ├── ModelInterceptors │ │ ├── InvalidOrderException.cs │ │ ├── SalesOrderCalculationsInterceptors.cs │ │ └── SalesOrderValidationInterceptor.cs │ │ ├── OrderingService.cs │ │ ├── PriceCalculator.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Sales.Services.csproj │ │ ├── SalesServicesModule.cs │ │ ├── app.config │ │ └── packages.config ├── UI │ ├── ConsoleApplication │ │ ├── AdventureWorksTestQueries │ │ │ ├── SalesOrdersHeader.sql │ │ │ └── SalesPersons.sql │ │ ├── App.config │ │ ├── AppConsole.cs │ │ ├── ConsoleApplication.csproj │ │ ├── IConsole.cs │ │ ├── OnModuleIsAliveConsole.cs │ │ ├── OrdersConsoleApplication.cs │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ └── WpfApplication │ │ ├── App.config │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ │ ├── WpfApplication.csproj │ │ └── packages.config └── _App_Data │ ├── readme.html │ └── readme.md ├── DesignPatterns ├── CodeDesign-DesignPatterns.sln └── ConsoleDemo │ ├── AbstractFactory │ ├── AbstractFactory.cs │ ├── AnimalWorld.cs │ ├── ScrollBar.cs │ ├── WidgetFactory.cs │ ├── WidgetsClientApp.cs │ └── Window.cs │ ├── App.config │ ├── ChainOfResponsibility │ ├── 011_PurchaseOrderApprover.cs │ ├── 01_PurchaseOrder.cs │ ├── 021_RequestHandler.cs │ ├── 022_Handlers.cs │ ├── 023_FileManager2.cs │ ├── 02_FileManager.cs │ └── PurchaseOrder.cs │ ├── Composite │ ├── 00_Client.cs │ ├── 01_IGraphicElement.cs │ ├── 02_Leafs.cs │ ├── 03_Composites.cs │ ├── 10_Client.cs │ ├── 11_GraphicElement.cs │ ├── 12_Leafs.cs │ ├── 13_Composites.cs │ ├── Extension.cs │ └── Extension1.cs │ ├── ConsoleDemo.csproj │ ├── Decorator │ ├── 01_ScrollWindow.cs │ ├── 02_ScrollBarWindow.cs │ └── _Client.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Strategy │ ├── 01_Robots.cs │ ├── 02_Robot_.cs │ ├── 031_Composition.cs │ ├── 03_Composition_.cs │ ├── 04_GenericRobot.cs │ ├── Coordonates.cs │ ├── ITextWrappingStrategy.cs │ └── _RobotsClient.cs │ └── Visitor │ ├── .readme.html │ ├── .readme.md │ ├── ICrmService.cs │ ├── IUnitOfWork.cs │ ├── OrderLine.cs │ ├── Product.cs │ ├── UofFactory.cs │ ├── v0 │ ├── Commands.cs │ └── CommandsManager.cs │ ├── v1 │ ├── Client.cs │ └── Command.cs │ ├── v2 │ ├── Client.cs │ └── Command.cs │ ├── v3 │ ├── Client.cs │ ├── Commands.cs │ ├── CommandsRepository.cs │ ├── DemoData.cs │ ├── IVisitable.cs │ ├── IVisitor.cs │ ├── NewCustomerCommandApprover.cs │ ├── PurchaseOrderCommandApprover.cs │ ├── ReportVisitor.cs │ ├── SalesOrderCommandApprover.cs │ └── VisitorDemo.cs │ ├── v4 │ ├── Client.cs │ ├── Commands.cs │ ├── CommandsRepository.cs │ ├── DemoData.cs │ ├── IVisitable.cs │ ├── IVisitor.cs │ ├── NewCustomerCommandApprover.cs │ ├── PurchaseOrderCommandApprover.cs │ ├── ReportVisitor.cs │ ├── SalesOrderCommandApprover.cs │ ├── Visitor.cs │ └── VisitorDemo.cs │ ├── v5 │ ├── Client.cs │ ├── Commands.cs │ ├── CommandsRepository.cs │ ├── DemoData.cs │ ├── IVisitable.cs │ ├── IVisitor.cs │ ├── NewCustomerCommandApporver.cs │ ├── PurchaseOrderCommandApprover.cs │ ├── Report.cs │ ├── ReportVisitor.cs │ ├── SalesOrderCommandApprover.cs │ ├── Visitor.cs │ └── VisitorDemo.cs │ └── v6 │ ├── Client.cs │ ├── Commands.cs │ ├── CommandsRepository.cs │ ├── DemoData.cs │ ├── IVisitable.cs │ ├── IVisitor.cs │ ├── NewCustomerCommandApporver.cs │ ├── PurchaseOrderCommandApprover.cs │ ├── ReportVisitor.cs │ ├── SalesOrderCommandApprover.cs │ ├── Visitor.cs │ └── VisitorDemo.cs ├── InterProcessCommunication └── TradingApp │ ├── .Notes │ ├── PresentationScript.html │ ├── PresentationScript.md │ ├── md-styles.css │ └── md-template.html │ ├── AppBootEx │ ├── AppBootEx.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ServiceProxyAttribute.cs │ └── ServiceProxyRegistrationBehavior.cs │ ├── ConsoleHost │ ├── .Deployment │ │ ├── ConsoleHost.portfolio.config │ │ ├── ConsoleHost.quotation.config │ │ ├── ConsoleHost.sales.config │ │ ├── Deploy-HostAll.bat │ │ ├── Deploy-HostEach.bat │ │ ├── Deploy-HostPortfolio.bat │ │ ├── Deploy-HostQuotation.bat │ │ ├── Deploy-HostSales.bat │ │ └── startAll.bat │ ├── App.config │ ├── AppBootBootstrapper.cs │ ├── ConsoleHost.csproj │ ├── Controllers │ │ ├── OrdersController.cs │ │ ├── PortfolioController.cs │ │ └── QuotationController.cs │ ├── Filters │ │ └── ConsoleLogFilter.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Startup.cs │ ├── ConsoleUi │ ├── .Deployment │ │ └── Deploy-ConsoleUi-ProxyOnly.bat │ ├── App.config │ ├── ConsoleEx.cs │ ├── ConsoleUi.csproj │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs │ ├── Infrastructure │ ├── Common │ │ └── Infra.Hosts │ │ │ ├── Infra.Hosts.csproj │ │ │ ├── ModulesHostContainer.cs │ │ │ └── Properties │ │ │ └── AssemblyInfo.cs │ └── Proxies │ │ ├── HttpHelpers.cs │ │ ├── OrdersServiceProxy.cs │ │ ├── PortfolioServiceProxy.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Proxies.csproj │ │ ├── ProxiesModule.cs │ │ ├── QuotationServiceProxy.cs │ │ └── app.config │ ├── MigrationBackup │ ├── 00c682d4 │ │ └── Infrastructure │ │ │ └── Infra.Hosts │ │ │ ├── Infra.Hosts.csproj │ │ │ ├── NuGetUpgradeLog.html │ │ │ └── packages.config │ ├── 13c6add7 │ │ └── ConsoleUi │ │ │ ├── ConsoleUi.csproj │ │ │ ├── NuGetUpgradeLog.html │ │ │ └── packages.config │ ├── 1abf21ee │ │ └── Infrastructure │ │ │ └── AppBootEx │ │ │ ├── AppBootEx.csproj │ │ │ ├── NuGetUpgradeLog.html │ │ │ └── packages.config │ ├── 637404f9 │ │ └── ConsoleHost │ │ │ ├── ConsoleHost.csproj │ │ │ ├── NuGetUpgradeLog.html │ │ │ └── packages.config │ ├── 6a755282 │ │ └── Modules │ │ │ └── Quotations │ │ │ └── Quotations.Services │ │ │ ├── NuGetUpgradeLog.html │ │ │ ├── Quotations.Services.csproj │ │ │ └── packages.config │ ├── 99eadac7 │ │ └── Modules │ │ │ └── Sales │ │ │ └── Sales.Services │ │ │ ├── NuGetUpgradeLog.html │ │ │ ├── Sales.Services.csproj │ │ │ └── packages.config │ ├── 9d36020b │ │ └── Modules │ │ │ └── Portfolio │ │ │ └── Portfolio.Services │ │ │ ├── NuGetUpgradeLog.html │ │ │ ├── Portfolio.Services.csproj │ │ │ └── packages.config │ └── ab5e6800 │ │ └── Infrastructure │ │ └── Proxies │ │ ├── NuGetUpgradeLog.html │ │ ├── Proxies.csproj │ │ └── packages.config │ ├── Modules │ ├── Portfolio │ │ └── Portofolio.Services │ │ │ ├── Portfolio.Services.csproj │ │ │ ├── PortfolioModule.cs │ │ │ ├── PortfolioService.cs │ │ │ └── Properties │ │ │ └── AssemblyInfo.cs │ ├── Quotation │ │ └── Quotation.Services │ │ │ └── QuotationService.cs │ ├── Quotations │ │ └── Quotation.Services │ │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ │ ├── QuotationService.cs │ │ │ ├── Quotations.Services.csproj │ │ │ └── QuotationsModule.cs │ ├── Sales │ │ └── Sales.Services │ │ │ ├── IRepository.cs │ │ │ ├── InMemoryRepository.cs │ │ │ ├── OrdersService.cs │ │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ │ ├── Sales.Services.csproj │ │ │ └── SalesModule.cs │ └── _Contracts │ │ ├── Contracts.csproj │ │ ├── Infrastructure │ │ └── IModulesHostContainer.cs │ │ ├── Portfolio.Services │ │ └── IPortfolioService.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Quotations.Services │ │ ├── IQuotationService.cs │ │ └── Quotation.cs │ │ └── Sales.Services │ │ ├── IOrdersService.cs │ │ └── LimitOrder.cs │ └── TradingApp.sln ├── LICENSE ├── LessonsSamples ├── LessonsSamples.sln └── LessonsSamples │ ├── App.config │ ├── Customer.cs │ ├── Lesson2 │ ├── querymanager.cpp │ └── querymanager.cs │ ├── Lesson5 │ ├── Class2.cs │ ├── ImageScale.cs │ ├── Line.cs │ ├── Modem.cs │ ├── Rectangle.cs │ ├── Shapes.cs │ └── TimedDoorAdapter.cs │ ├── Lesson6 │ ├── CoreContainerConstructorSelection │ │ ├── App.cs │ │ ├── IRootService.cs │ │ ├── IService1.cs │ │ ├── IService2.cs │ │ └── NetCoreConstructorSelectionDemo.cs │ ├── CoreContainerLifetime │ │ ├── App.cs │ │ ├── IOperation.cs │ │ ├── MyController.cs │ │ ├── NetCoreLifetimeDemo.cs │ │ ├── Operation.cs │ │ └── Service.cs │ ├── DI-Demo │ │ ├── AppConsole.cs │ │ ├── FileStorage.cs │ │ ├── IConsole.cs │ │ ├── IMovieConsoleCreator.cs │ │ ├── IMovieTranslator.cs │ │ ├── ITextStorage.cs │ │ ├── MovieConsoleApplication.cs │ │ ├── MovieTranslator.cs │ │ ├── NetCoreContainerDemo.cs │ │ ├── UnityDemo.cs │ │ ├── _Exercises.html │ │ └── _Exercises.md │ ├── DI_AndDisposable │ │ ├── Model.cs │ │ ├── Repository.cs │ │ ├── RepositoryFactory.cs │ │ ├── Service11.cs │ │ └── Service12.cs │ ├── Expenses │ │ ├── 1.ExpenseData.cs │ │ ├── 1.ExpensesService.cs │ │ ├── 1.IExpensesService.cs │ │ └── 2.Expense.cs │ ├── IMovieProvider.cs │ ├── Logger │ │ ├── LogEntry.cs │ │ └── Logger.cs │ ├── Movie.cs │ ├── MovieListerFactory.cs │ ├── MovieLister_DI.cs │ ├── MovieLister_InterafaceInj.cs │ ├── MovieLister_SL.cs │ └── ServiceLocatorTestability │ │ ├── INumberGeneratorService.cs │ │ ├── ServiceLocatorDoubleStorage.cs │ │ ├── TestRunner.cs │ │ ├── UnderTest.cs │ │ └── UnitTest.cs │ ├── Lesson7 │ ├── Class1.cs │ ├── CohesionCoupling │ │ ├── 00_PageXmlExport.cs │ │ ├── 01_PageXmlExport.cs │ │ ├── 02_PageXmlExport.cs │ │ ├── 03_PageXmlExport.cs │ │ ├── 04_PageXmlExport.cs │ │ ├── 05_PageXmlExport.cs │ │ ├── 10_PageXmlExportClient.cs │ │ ├── 11_PageXmlExportClient.cs │ │ ├── 12_PageXmlExportClientcs.cs │ │ ├── 13_PageXmlExportClient.cs │ │ ├── EfRepository.cs │ │ ├── ICrmService.cs │ │ ├── IExportDataProvider_4.cs │ │ ├── IExportDataProvider_5.cs │ │ ├── ILocationService.cs │ │ ├── IPageFileWriter.cs │ │ ├── IRepository.cs │ │ ├── PageData.cs │ │ └── PageXml.cs │ ├── ErrorHandling │ │ ├── CodeSnippet.cs │ │ └── DeviceController.cs │ ├── GoodClasses │ │ ├── DataModel │ │ │ ├── Repository.cs │ │ │ └── SalesOrder.cs │ │ └── Geometry │ │ │ ├── CircleGeometry.cs │ │ │ ├── GeometryCalculatorFactory.cs │ │ │ ├── IGeometryCalculator.cs │ │ │ ├── PolymorphicShapes.cs │ │ │ └── ProceduralShapes.cs │ └── InheritanceComposition │ │ ├── Account.cs │ │ ├── AccountClientCode.cs │ │ ├── AccountClientCodeTests.cs │ │ ├── AccountTests.cs │ │ ├── ILogMessageParser.cs │ │ ├── LogEntry.cs │ │ ├── LogSource.cd │ │ ├── LogSource.cs │ │ ├── LogSource_2.cd │ │ ├── LogSource_2.cs │ │ └── Month.cs │ ├── Lesson8 │ ├── AuditLog │ │ ├── EntityInterceptor.cs │ │ ├── IAuditLog.cs │ │ └── PatientAuditLogInterceptor.cs │ ├── RowLevelAuth │ │ ├── IRowAuthPoliciesContainer.cs │ │ ├── Repository.cs │ │ ├── RowAuthPoliciesContainer.cs │ │ ├── RowAuthPolicy.cs │ │ └── SomeService.cs │ └── Validation │ │ ├── AddressValidationRules.cs │ │ ├── Country.cs │ │ ├── EntityValidationRulesRegistrator.cs │ │ ├── IValidationRulesSet.cs │ │ └── ValidationMessages.cs │ ├── LessonsSamples.csproj │ ├── Point.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── packages.config ├── MultitenancySamples ├── SeparatedDbsConsoleDemo │ ├── SeparatedDbs.ConsoleDemo │ │ ├── App.config │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── SeparatedDbs.ConsoleDemo.csproj │ ├── SeparatedDbs.DataAccess │ │ ├── App.config │ │ ├── MultitenancyDbContextFactory.cs │ │ ├── PhysioEntities.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── SeparatedDbs.DataAccess.csproj │ │ └── packages.config │ └── SeparatedDbsConsoleDemo.sln └── SharedDbConsoleDemo │ ├── SharedDb.ConsoleDemo │ ├── App.config │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SharedDb.ConsoleDemo.csproj │ └── packages.config │ ├── SharedDb.DataAccess │ ├── App.config │ ├── DbContextFactory.cs │ ├── Diagnostic.cs │ ├── EmptyInterceptorsResolver.cs │ ├── ITenantEntity.cs │ ├── Patient.cs │ ├── PatientFile.cs │ ├── PatientHistory.cs │ ├── Physio.Context.cs │ ├── Physio.Context.tt │ ├── Physio.Designer.cs │ ├── Physio.cs │ ├── Physio.edmx │ ├── Physio.edmx.diagram │ ├── Physio.tt │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Repository.cs │ ├── SharedDb.DataAccess.csproj │ ├── Tenant.cs │ ├── TenantEntities.cs │ └── packages.config │ ├── SharedDb.Database │ ├── RefactorToMultitenancy.publish.sql │ ├── SharedDb.Database.sqlproj │ └── dbo │ │ └── Tables │ │ ├── Diagnostics.sql │ │ ├── PatientFile.sql │ │ ├── PatientHistory.sql │ │ ├── Patients.sql │ │ └── Tenants.sql │ └── SharedDbConsoleDemo.sln └── README.md /AppInfraDemo/.Exercises/PointsOfAttention.md: -------------------------------------------------------------------------------- 1 | # Enforce Data Access Layer and Business Logic Layer separation 2 | 3 | - No assembly except the `*.DataAccess` ones are allowed to reference the `Entity Framework` 4 | 5 | - By default the EF generates the DTOs in the same project w/ the `DbContext`. This does not enforce the separation. 6 | 7 | - We should change the generator to put in the `DataAccess` the `DbContext` needed for implementing the `Repository` and `UnitOfWork` and in the Sales Module the DTOs as they are its Data Model 8 | 9 | - The tag `Infra_DataAccessDependsOnSales` shows a first step on doing this. 10 | - however, here there is "wrong" reference from the `DataAccess` to the Sales Modules assembly 11 | 12 | - The tag `Infra_DataAccessDependencyOnSalesRemoved` shows how this reference is inverted by using the `IDbContextFactory` abstraction 13 | -------------------------------------------------------------------------------- /AppInfraDemo/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # DV2002: Unmapped types 4 | dotnet_diagnostic.DV2002.severity = silent 5 | -------------------------------------------------------------------------------- /AppInfraDemo/ClassDiagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onCodeDesign/Code-Design-Training/738d05aae78965ec7825606b5da2915aa28194e4/AppInfraDemo/ClassDiagram.png -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/Common/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/Common/DataModel/Abstractions/Demo_IAuditable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Common.DataModel.Abstractions 4 | { 5 | public interface IAuditable 6 | { 7 | DateTime? LastEditDate { get; set; } 8 | DateTime CreationDate { get; set; } 9 | string LastEditBy { get; set; } 10 | string CreatedBy { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/Common/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace DataAccess 4 | { 5 | static class CollectionExtensions 6 | { 7 | public static void AddIfNotExists(this ICollection list, T item) 8 | { 9 | if (list.Contains(item) == false) 10 | { 11 | list.Add(item); 12 | } 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/EntityInterceptor.cs: -------------------------------------------------------------------------------- 1 | namespace DataAccess 2 | { 3 | public abstract class EntityInterceptor : IEntityInterceptor 4 | where TEntity : class 5 | { 6 | public virtual void OnLoad(IEntityEntryFacade entry, IRepository repository) 7 | { 8 | } 9 | 10 | public virtual void OnSave(IEntityEntryFacade entry, IRepository repository) 11 | { 12 | } 13 | 14 | public virtual void OnEntityRemoved(IEntityEntryFacade entry, IRepository repository) 15 | { 16 | } 17 | 18 | public void OnLoad(IEntityEntryFacade entry, IRepository repository) 19 | { 20 | this.OnLoad(entry.Convert(), repository); 21 | } 22 | 23 | public void OnSave(IEntityEntryFacade entity, IRepository repository) 24 | { 25 | this.OnSave(entity.Convert(), repository); 26 | } 27 | 28 | public void OnEntityRemoved(IEntityEntryFacade entity, IRepository repository) 29 | { 30 | this.OnEntityRemoved(entity.Convert(), repository); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/DataValidationResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace DataAccess.Exceptions 6 | { 7 | [Serializable] 8 | public class DataValidationResult 9 | { 10 | private readonly List errors; 11 | 12 | public DataValidationResult(IEntityEntryFacade entry, IEnumerable errors) 13 | { 14 | Entry = entry; 15 | this.errors = errors.ToList(); 16 | } 17 | 18 | public IEntityEntryFacade Entry { get; private set; } 19 | 20 | public IEnumerable Errors 21 | { 22 | get { return errors; } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/DateTimeRangeRepositoryException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.SqlClient; 3 | using System.Runtime.Serialization; 4 | 5 | namespace DataAccess.Exceptions 6 | { 7 | [Serializable] 8 | public class DateTimeRangeRepositoryException : RepositoryException 9 | { 10 | public DateTimeRangeRepositoryException() 11 | { 12 | } 13 | 14 | public DateTimeRangeRepositoryException(string errorMessage) 15 | : base(errorMessage) 16 | { 17 | } 18 | 19 | public DateTimeRangeRepositoryException(SqlException exception) 20 | : base(exception) 21 | { 22 | } 23 | 24 | public DateTimeRangeRepositoryException(string message, Exception exception) 25 | : base(message, exception) 26 | { 27 | } 28 | 29 | protected DateTimeRangeRepositoryException(SerializationInfo info, StreamingContext context) 30 | : base(info, context) 31 | { 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/DeadlockVictimRepositoryException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.SqlClient; 3 | using System.Runtime.Serialization; 4 | 5 | namespace DataAccess.Exceptions 6 | { 7 | [Serializable] 8 | public class DeadlockVictimRepositoryException : RepositoryException 9 | { 10 | public DeadlockVictimRepositoryException() 11 | { 12 | } 13 | 14 | public DeadlockVictimRepositoryException(string errorMessage) 15 | : base(errorMessage) 16 | { 17 | } 18 | 19 | public DeadlockVictimRepositoryException(SqlException exception) 20 | : base(exception) 21 | { 22 | } 23 | 24 | public DeadlockVictimRepositoryException(string message, Exception exception) 25 | : base(message, exception) 26 | { 27 | } 28 | 29 | protected DeadlockVictimRepositoryException(SerializationInfo info, StreamingContext context) 30 | : base(info, context) 31 | { 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/DeleteConstraintRepositoryException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.SqlClient; 3 | using System.Runtime.Serialization; 4 | 5 | namespace DataAccess.Exceptions 6 | { 7 | [Serializable] 8 | public class DeleteConstraintRepositoryException : RepositoryException 9 | { 10 | public DeleteConstraintRepositoryException() 11 | { 12 | } 13 | 14 | public DeleteConstraintRepositoryException(string errorMessage) 15 | : base(errorMessage) 16 | { 17 | } 18 | 19 | public DeleteConstraintRepositoryException(SqlException exception) 20 | : base(exception) 21 | { 22 | } 23 | 24 | public DeleteConstraintRepositoryException(string message, Exception exception) 25 | : base(message, exception) 26 | { 27 | } 28 | 29 | protected DeleteConstraintRepositoryException(SerializationInfo info, StreamingContext context) 30 | : base(info, context) 31 | { 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/Handlers/ConcurrencyExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Entity.Core; 3 | using iQuarc.SystemEx; 4 | 5 | namespace DataAccess.Exceptions.Handlers 6 | { 7 | class ConcurrencyExceptionHandler : IExceptionHandler 8 | { 9 | private readonly IExceptionHandler successor; 10 | 11 | public ConcurrencyExceptionHandler(IExceptionHandler successor) 12 | { 13 | this.successor = successor; 14 | } 15 | 16 | public void Handle(Exception exception) 17 | { 18 | var concurrencyException = exception.FirstInner(); 19 | if (concurrencyException != null) 20 | { 21 | throw new ConcurrencyRepositoryException(concurrencyException); 22 | } 23 | 24 | successor.Handle(exception); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/Handlers/DefaultExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess.Exceptions.Handlers 4 | { 5 | class DefaultExceptionHandler : IExceptionHandler 6 | { 7 | public void Handle(Exception exception) 8 | { 9 | throw new RepositoryException(exception); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/Handlers/ExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess.Exceptions.Handlers 4 | { 5 | class ExceptionHandler : IExceptionHandler 6 | { 7 | private readonly IExceptionHandler chainHead = 8 | new SqlExceptionHandler( 9 | new ConcurrencyExceptionHandler( 10 | new UpdateExceptionHandler( 11 | new DbEntityValidationExceptionHandler( 12 | new DefaultExceptionHandler()))) 13 | ); 14 | 15 | public void Handle(Exception exception) 16 | { 17 | chainHead.Handle(exception); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/Handlers/IExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess.Exceptions.Handlers 4 | { 5 | interface IExceptionHandler 6 | { 7 | void Handle(Exception exception); 8 | } 9 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/Handlers/UpdateExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Entity.Core; 3 | using iQuarc.SystemEx; 4 | 5 | namespace DataAccess.Exceptions.Handlers 6 | { 7 | class UpdateExceptionHandler : IExceptionHandler 8 | { 9 | private readonly IExceptionHandler successor; 10 | 11 | public UpdateExceptionHandler(IExceptionHandler successor) 12 | { 13 | this.successor = successor; 14 | } 15 | 16 | public void Handle(Exception exception) 17 | { 18 | var updateException = exception.FirstInner(); 19 | if (updateException != null) 20 | { 21 | throw new RepositoryUpdateException(updateException); 22 | } 23 | 24 | successor.Handle(exception); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/RepositoryUpdateException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace DataAccess.Exceptions 5 | { 6 | [Serializable] 7 | public class RepositoryUpdateException : RepositoryException 8 | { 9 | public RepositoryUpdateException() 10 | { 11 | } 12 | 13 | public RepositoryUpdateException(string errorMessage) 14 | : base(errorMessage) 15 | { 16 | } 17 | 18 | public RepositoryUpdateException(Exception exception) 19 | : base(exception) 20 | { 21 | } 22 | 23 | public RepositoryUpdateException(string message, Exception exception) 24 | : base(message, exception) 25 | { 26 | } 27 | 28 | protected RepositoryUpdateException(SerializationInfo info, StreamingContext context) 29 | : base(info, context) 30 | { 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/UniqueConstraintRepositoryException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.SqlClient; 3 | using System.Runtime.Serialization; 4 | 5 | namespace DataAccess.Exceptions 6 | { 7 | [Serializable] 8 | public class UniqueConstraintRepositoryException : RepositoryException 9 | { 10 | public UniqueConstraintRepositoryException() 11 | { 12 | } 13 | 14 | public UniqueConstraintRepositoryException(string errorMessage) 15 | : base(errorMessage) 16 | { 17 | } 18 | 19 | public UniqueConstraintRepositoryException(SqlException exception) 20 | : base(exception) 21 | { 22 | } 23 | 24 | public UniqueConstraintRepositoryException(string message, Exception exception) 25 | : base(message, exception) 26 | { 27 | } 28 | 29 | protected UniqueConstraintRepositoryException(SerializationInfo info, StreamingContext context) 30 | : base(info, context) 31 | { 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/Exceptions/ValidationError.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess.Exceptions 4 | { 5 | [Serializable] 6 | public class ValidationError 7 | { 8 | public ValidationError(string propertyName, string errorMessage) 9 | { 10 | PropertyName = propertyName; 11 | ErrorMessage = errorMessage; 12 | } 13 | 14 | public string PropertyName { get; private set; } 15 | public string ErrorMessage { get; private set; } 16 | } 17 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/IDbContextFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity; 2 | 3 | namespace DataAccess 4 | { 5 | public interface IDbContextFactory 6 | { 7 | DbContext CreateContext(); 8 | } 9 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/IEntityEntryFacade.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess 4 | { 5 | public interface IEntityEntryFacade 6 | { 7 | object Entity { get; } 8 | EntityEntryStates State { get; } 9 | object GetOriginalValue(string propertyName); 10 | IEntityEntryFacade Convert() where T : class; 11 | void SetOriginalValue(string propertyName, object value); 12 | } 13 | 14 | public interface IEntityEntryFacade 15 | where T : class 16 | { 17 | T Entity { get; } 18 | EntityEntryStates State { get; } 19 | object GetOriginalValue(string propertyName); 20 | void SetOriginalValue(string propertyName, object value); 21 | } 22 | 23 | [Flags] 24 | public enum EntityEntryStates 25 | { 26 | Detached = 1, 27 | Unchanged = 2, 28 | Added = 4, 29 | Deleted = 8, 30 | Modified = 16, 31 | } 32 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/IEntityInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess 4 | { 5 | public interface IEntityInterceptor 6 | { 7 | void OnLoad(IEntityEntryFacade entry, IRepository repository); 8 | void OnSave(IEntityEntryFacade entity, IRepository repository); 9 | void OnEntityRemoved(IEntityEntryFacade entity, IRepository repository); 10 | } 11 | 12 | public interface IEntityInterceptor : IEntityInterceptor 13 | where T : class 14 | { 15 | void OnLoad(IEntityEntryFacade entry, IRepository repository); 16 | void OnSave(IEntityEntryFacade entry, IRepository repository); 17 | void OnEntityRemoved(IEntityEntryFacade entity, IRepository repository); 18 | } 19 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/IRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace DataAccess 4 | { 5 | public interface IRepository 6 | { 7 | IQueryable GetEntities() where TDbEntity : class; 8 | IUnitOfWork CreateUnitOfWork(); 9 | } 10 | } -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DataAccess/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AppInfraDemo/Infrastructure/DependencyValidation/DependencyValidation.layerdiagram.suppressions: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Crm/ICrmService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Contracts.Crm 8 | { 9 | public interface ICrmService 10 | { 11 | CustomerInfo GetCustomerInfo(string customerName); 12 | } 13 | 14 | public class CustomerInfo 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Location/ILocationService.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Location 2 | { 3 | public interface ILocationService 4 | { 5 | Coordinates GetCoordinates(string city, string street, string number); 6 | } 7 | 8 | public class Coordinates 9 | { 10 | public double Latitude { get; set; } 11 | public double Longitude { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Notifications/IAmAliveSubscriber.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Notifications 2 | { 3 | public interface IAmAliveSubscriber 4 | { 5 | void AmAlive(T item); 6 | } 7 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Notifications/INotificationService.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Notifications 2 | { 3 | public interface INotificationService 4 | { 5 | void NotifyNew(T item); 6 | void NotifyDeleted(T item); 7 | void NotifyChanged(T item); 8 | void NotifyStatusChange(T item, Status newStatus, Status oldStatus); 9 | void NotifyAlive(T item); 10 | } 11 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Notifications/IStateChangeSubscriber.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Notifications 2 | { 3 | public interface IStateChangeSubscriber 4 | { 5 | void NewItem(T item); 6 | void NotifyDeleted(T item); 7 | void NotifyChanged(T item); 8 | } 9 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Notifications/Status.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Contracts.Notifications 4 | { 5 | [Flags] 6 | public enum Status 7 | { 8 | New = 0, 9 | PreProcess = 2, 10 | InProgress = 4, 11 | PreApprove = 8, 12 | Approved = 16, 13 | Rejected = 32, 14 | OnHold = 64, 15 | Deleted = 128 16 | } 17 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Sales/IOrderingService.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Sales 2 | { 3 | public interface IOrderingService 4 | { 5 | SalesOrderResult PlaceOrder(string customerName, OrderRequest request); 6 | 7 | SalesOrderInfo[] GetOrdersInfo(string customerName); 8 | } 9 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Sales/OrderRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Sales 2 | { 3 | public class OrderRequest 4 | { 5 | public ProductQuantity[] Products { get; set; } 6 | } 7 | 8 | public class ProductQuantity 9 | { 10 | public ProductDescription Product { get; set; } 11 | public float Quantity { get; set; } 12 | public UnitOfMeasure Unit { get; set; } 13 | } 14 | 15 | public class ProductDescription 16 | { 17 | public int? ProductId { get; set; } 18 | public string Code { get; set; } 19 | public string Description { get; set; } 20 | } 21 | 22 | public enum UnitOfMeasure 23 | { 24 | Item, 25 | Kilograms, 26 | Liters 27 | } 28 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Sales/SalesOrderInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Contracts.Sales 4 | { 5 | public class SalesOrderInfo 6 | { 7 | public string CustomerName { get; set; } 8 | public string Number { get; set; } 9 | 10 | public string SalesPersonName { get; set; } 11 | 12 | public DateTime DueDate { get; set; } 13 | 14 | public decimal TotalDue { get; set; } 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/Sales/SalesOrderResult.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Sales 2 | { 3 | public class SalesOrderResult 4 | { 5 | public int OrderId { get; set; } 6 | public OrderResultState State { get; set; } 7 | public string Message { get; set; } 8 | } 9 | 10 | public enum OrderResultState 11 | { 12 | /// 13 | /// Technical unknown error 14 | /// 15 | Error, 16 | 17 | /// 18 | /// Order placement was successful 19 | /// 20 | Placed, 21 | 22 | /// 23 | /// Order wasn't placed because of business rules 24 | /// 25 | Failure, 26 | 27 | /// 28 | /// The order request was invalid. 29 | /// The order was not placed 30 | /// 31 | Invalid 32 | } 33 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Contracts/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/DataModel/Customer.cs: -------------------------------------------------------------------------------- 1 | namespace DataModel 2 | { 3 | public class Customer 4 | { 5 | public string Name { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/DataModel/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataModel 4 | { 5 | public class Order 6 | { 7 | public Customer Customer { get; set; } 8 | public DateTime Date { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/DataModel/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/Category.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Export.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Category 16 | { 17 | public Category() 18 | { 19 | this.Products = new HashSet(); 20 | } 21 | 22 | public int CategoryID { get; set; } 23 | public string CategoryName { get; set; } 24 | public string Description { get; set; } 25 | public byte[] Picture { get; set; } 26 | 27 | public virtual ICollection Products { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/CustomerDemographic.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Export.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class CustomerDemographic 16 | { 17 | public CustomerDemographic() 18 | { 19 | this.Customers = new HashSet(); 20 | } 21 | 22 | public string CustomerTypeID { get; set; } 23 | public string CustomerDesc { get; set; } 24 | 25 | public virtual ICollection Customers { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/ExportEntities.Designer.cs: -------------------------------------------------------------------------------- 1 | // T4 code generation is enabled for model 'C:\D\Work\Training\OOD\git\AppInfraDemo\Modules\Export\Export.DataModel\ExportEntities.edmx'. 2 | // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer 3 | // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model 4 | // is open in the designer. 5 | 6 | // If no context and entity classes have been generated, it may be because you created an empty model but 7 | // have not yet chosen which version of Entity Framework to use. To generate a context class and entity 8 | // classes for your model, open the model in the designer, right-click on the designer surface, and 9 | // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation 10 | // Item...'. -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/ExportEntities.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/Order_Detail.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Export.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Order_Detail 16 | { 17 | public int OrderID { get; set; } 18 | public int ProductID { get; set; } 19 | public decimal UnitPrice { get; set; } 20 | public short Quantity { get; set; } 21 | public float Discount { get; set; } 22 | 23 | public virtual Order Order { get; set; } 24 | public virtual Product Product { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/Region.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Export.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Region 16 | { 17 | public Region() 18 | { 19 | this.Territories = new HashSet(); 20 | } 21 | 22 | public int RegionID { get; set; } 23 | public string RegionDescription { get; set; } 24 | 25 | public virtual ICollection Territories { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/Shipper.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Export.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Shipper 16 | { 17 | public Shipper() 18 | { 19 | this.Orders = new HashSet(); 20 | } 21 | 22 | public int ShipperID { get; set; } 23 | public string CompanyName { get; set; } 24 | public string Phone { get; set; } 25 | 26 | public virtual ICollection Orders { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/Territory.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Export.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Territory 16 | { 17 | public Territory() 18 | { 19 | this.Employees = new HashSet(); 20 | } 21 | 22 | public string TerritoryID { get; set; } 23 | public string TerritoryDescription { get; set; } 24 | public int RegionID { get; set; } 25 | 26 | public virtual Region Region { get; set; } 27 | public virtual ICollection Employees { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.DataModel/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.Services/PageXmlDemo/CustomerData.cs: -------------------------------------------------------------------------------- 1 | namespace Export.Services.PageXmlDemo 2 | { 3 | public class CustomerData 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.Services/PageXmlDemo/PageData.cs: -------------------------------------------------------------------------------- 1 | namespace Export.Services.PageXmlDemo 2 | { 3 | public class PageData 4 | { 5 | public CustomerData CustomerData { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.Services/PageXmlDemo/PageXml.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Export.Services.PageXmlDemo 4 | { 5 | public class PageXml 6 | { 7 | public CustomerXml Customer { get; set; } 8 | } 9 | 10 | public class CustomerXml 11 | { 12 | public string Name { get; set; } 13 | public List Addresses { get; set; } 14 | } 15 | 16 | public class AddressXml 17 | { 18 | public string Street { get; set; } 19 | public string City { get; set; } 20 | public string Number { get; set; } 21 | public string Coordinates { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Export/Export.Services/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Notifications/Notification.Services/OrderStateChangeSubscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Contracts.Notifications; 3 | using Contracts.Sales; 4 | using iQuarc.AppBoot; 5 | 6 | namespace Notifications 7 | { 8 | [Service("Order Default Subscriber", typeof (IStateChangeSubscriber))] 9 | class OrderStateChangeSubscriber : IStateChangeSubscriber 10 | { 11 | public void NewItem(SalesOrderResult item) 12 | { 13 | //TODO: We've got new order!!! 14 | } 15 | 16 | public void NotifyDeleted(SalesOrderResult item) 17 | { 18 | throw new NotImplementedException(); 19 | } 20 | 21 | public void NotifyChanged(SalesOrderResult item) 22 | { 23 | throw new NotImplementedException(); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Notifications/Notification.Services/StateChangeSubscriber.cs: -------------------------------------------------------------------------------- 1 | using Contracts.Notifications; 2 | using iQuarc.AppBoot; 3 | 4 | namespace Notifications 5 | { 6 | [Service("Default Change Subscriber", typeof (IStateChangeSubscriber<>))] 7 | class StateChangeSubscriber : IStateChangeSubscriber 8 | { 9 | public void NewItem(T item) 10 | { 11 | //TODO: write to monitoring dashboard 12 | } 13 | 14 | public void NotifyDeleted(T item) 15 | { 16 | //TODO: write to monitoring dashboard 17 | } 18 | 19 | public void NotifyChanged(T item) 20 | { 21 | //TODO: write to monitoring dashboard 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Notifications/Notification.Services/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Notifications/Notification.Services/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataAccess/DbContextFactory.cs: -------------------------------------------------------------------------------- 1 | using iQuarc.AppBoot; 2 | using iQuarc.DataAccess; 3 | 4 | namespace Sales.DataAccess 5 | { 6 | [Service(typeof(IDbContextFactory))] 7 | public class DbContextFactory : DbContextFactory 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataAccess/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/App.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/CountryRegionCurrency.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class CountryRegionCurrency 16 | { 17 | public string CountryRegionCode { get; set; } 18 | public string CurrencyCode { get; set; } 19 | public System.DateTime ModifiedDate { get; set; } 20 | 21 | public virtual Currency Currency { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/PersonCreditCard.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class PersonCreditCard 16 | { 17 | public int BusinessEntityID { get; set; } 18 | public int CreditCardID { get; set; } 19 | public System.DateTime ModifiedDate { get; set; } 20 | 21 | public virtual CreditCard CreditCard { get; set; } 22 | public virtual Person Person { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SalesEntities.Designer.cs: -------------------------------------------------------------------------------- 1 | // T4 code generation is enabled for model 'C:\D\Work\Training\OOD\git\AppInfraDemo\Modules\Sales\Sales.DataModel\SalesEntities.edmx'. 2 | // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer 3 | // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model 4 | // is open in the designer. 5 | 6 | // If no context and entity classes have been generated, it may be because you created an empty model but 7 | // have not yet chosen which version of Entity Framework to use. To generate a context class and entity 8 | // classes for your model, open the model in the designer, right-click on the designer surface, and 9 | // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation 10 | // Item...'. -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SalesEntities.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SalesOrderHeaderSalesReason.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class SalesOrderHeaderSalesReason 16 | { 17 | public int SalesOrderID { get; set; } 18 | public int SalesReasonID { get; set; } 19 | public System.DateTime ModifiedDate { get; set; } 20 | 21 | public virtual SalesOrderHeader SalesOrderHeader { get; set; } 22 | public virtual SalesReason SalesReason { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SalesPersonQuotaHistory.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class SalesPersonQuotaHistory 16 | { 17 | public int BusinessEntityID { get; set; } 18 | public System.DateTime QuotaDate { get; set; } 19 | public decimal SalesQuota { get; set; } 20 | public System.Guid rowguid { get; set; } 21 | public System.DateTime ModifiedDate { get; set; } 22 | 23 | public virtual SalesPerson SalesPerson { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SalesReason.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class SalesReason 16 | { 17 | public SalesReason() 18 | { 19 | this.SalesOrderHeaderSalesReasons = new HashSet(); 20 | } 21 | 22 | public int SalesReasonID { get; set; } 23 | public string Name { get; set; } 24 | public string ReasonType { get; set; } 25 | public System.DateTime ModifiedDate { get; set; } 26 | 27 | public virtual ICollection SalesOrderHeaderSalesReasons { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SalesTaxRate.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class SalesTaxRate 16 | { 17 | public int SalesTaxRateID { get; set; } 18 | public int StateProvinceID { get; set; } 19 | public byte TaxType { get; set; } 20 | public decimal TaxRate { get; set; } 21 | public string Name { get; set; } 22 | public System.Guid rowguid { get; set; } 23 | public System.DateTime ModifiedDate { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SalesTerritoryHistory.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class SalesTerritoryHistory 16 | { 17 | public int BusinessEntityID { get; set; } 18 | public int TerritoryID { get; set; } 19 | public System.DateTime StartDate { get; set; } 20 | public Nullable EndDate { get; set; } 21 | public System.Guid rowguid { get; set; } 22 | public System.DateTime ModifiedDate { get; set; } 23 | 24 | public virtual SalesPerson SalesPerson { get; set; } 25 | public virtual SalesTerritory SalesTerritory { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/ShoppingCartItem.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class ShoppingCartItem 16 | { 17 | public int ShoppingCartItemID { get; set; } 18 | public string ShoppingCartID { get; set; } 19 | public int Quantity { get; set; } 20 | public int ProductID { get; set; } 21 | public System.DateTime DateCreated { get; set; } 22 | public System.DateTime ModifiedDate { get; set; } 23 | 24 | public virtual Product Product { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/SpecialOfferProduct.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class SpecialOfferProduct 16 | { 17 | public SpecialOfferProduct() 18 | { 19 | this.SalesOrderDetails = new HashSet(); 20 | } 21 | 22 | public int SpecialOfferID { get; set; } 23 | public int ProductID { get; set; } 24 | public System.Guid rowguid { get; set; } 25 | public System.DateTime ModifiedDate { get; set; } 26 | 27 | public virtual ICollection SalesOrderDetails { get; set; } 28 | public virtual SpecialOffer SpecialOffer { get; set; } 29 | public virtual Product Product { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/Store.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace Sales.DataModel 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Store 16 | { 17 | public Store() 18 | { 19 | this.Customers = new HashSet(); 20 | } 21 | 22 | public int BusinessEntityID { get; set; } 23 | public string Name { get; set; } 24 | public Nullable SalesPersonID { get; set; } 25 | public string Demographics { get; set; } 26 | public System.Guid rowguid { get; set; } 27 | public System.DateTime ModifiedDate { get; set; } 28 | 29 | public virtual ICollection Customers { get; set; } 30 | public virtual SalesPerson SalesPerson { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/Values/SalesOrderHeaderStatusValues.cs: -------------------------------------------------------------------------------- 1 | namespace Sales.DataModel.Values 2 | { 3 | public static class SalesOrderHeaderStatusValues 4 | { 5 | public const byte InProcess = 1; 6 | public const byte Approved = 2; 7 | public const byte Backordered = 3; 8 | public const byte Rejected = 4; 9 | public const byte Shipped = 5; 10 | public const byte Cancelled = 6; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.DataModel/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.Services/IApprovalService.cs: -------------------------------------------------------------------------------- 1 | namespace Sales 2 | { 3 | internal interface IApprovalService 4 | { 5 | bool Approve(ApproveRequest approveRequest); 6 | } 7 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.Services/ModelInterceptors/InvalidOrderException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Sales.ModelInterceptors 4 | { 5 | class InvalidOrderException : Exception 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.Services/PriceCalculator.cs: -------------------------------------------------------------------------------- 1 | using Contracts.Sales; 2 | using iQuarc.AppBoot; 3 | using Sales.DataModel; 4 | 5 | namespace Sales 6 | { 7 | interface IPriceCalculator 8 | { 9 | decimal CalculateTaxes(OrderRequest o, Customer c); 10 | 11 | decimal CalculateDiscount(OrderRequest o, Customer c); 12 | } 13 | 14 | [Service(typeof (IPriceCalculator), Lifetime.Instance)] 15 | class PriceCalculator : IPriceCalculator 16 | { 17 | public decimal CalculateTaxes(OrderRequest o, Customer c) 18 | { 19 | // do actual calculation 20 | return 10; 21 | } 22 | 23 | public decimal CalculateDiscount(OrderRequest o, Customer c) 24 | { 25 | // do actual calculation 26 | return 20; 27 | } 28 | } 29 | 30 | 31 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.Services/SalesServicesModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Contracts.Notifications; 3 | using iQuarc.AppBoot; 4 | 5 | namespace Sales 6 | { 7 | [Service("Sales Services Module", typeof(IModule))] 8 | class SalesServicesModule : IModule 9 | { 10 | private readonly INotificationService notificationService; 11 | 12 | public SalesServicesModule(INotificationService notificationService) 13 | { 14 | this.notificationService = notificationService; 15 | } 16 | 17 | public string Name 18 | { 19 | get { return "Sales Module"; } 20 | } 21 | 22 | public void Initialize() 23 | { 24 | IModule m = this; 25 | notificationService.NotifyAlive(m); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /AppInfraDemo/Modules/Sales/Sales.Services/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/ConsoleApplication/AdventureWorksTestQueries/SalesOrdersHeader.sql: -------------------------------------------------------------------------------- 1 | SELECT * FROM [Sales].[Customer] C 2 | INNER JOIN [Person].[Person] P ON C.PersonId = P.[BusinessEntityID] 3 | --WHERE C.CustomerID=11019 4 | 5 | SELECT CustomerID, count(*) as Orders 6 | FROM [Sales].[SalesOrderHeader] 7 | GROUP BY CustomerID 8 | 9 | SELECT * 10 | FROM [Sales].[SalesOrderHeader] SO 11 | INNER JOIN [Sales].[Customer] C ON SO.CustomerID=C.CustomerId 12 | INNER JOIN [Person].[Person] P ON P.BusinessEntityID=C.PersonId 13 | WHERE P.LastName='Abel' -------------------------------------------------------------------------------- /AppInfraDemo/UI/ConsoleApplication/AdventureWorksTestQueries/SalesPersons.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM [Sales].[SalesOrderHeader] SO 3 | INNER JOIN [Person].[Person] P ON P.BusinessEntityID=SO.SalesPersonId 4 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/ConsoleApplication/IConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleApplication 4 | { 5 | internal interface IConsole 6 | { 7 | string AskInput(string message); 8 | string ReadLine(); 9 | ConsoleKeyInfo ReadKey(); 10 | void WriteEntity(T entity); 11 | void WriteLine(string line); 12 | void Clear(); 13 | } 14 | } -------------------------------------------------------------------------------- /AppInfraDemo/UI/ConsoleApplication/OnModuleIsAliveConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Contracts.Notifications; 3 | using iQuarc.AppBoot; 4 | 5 | namespace ConsoleApplication 6 | { 7 | [Service("Module Is Alive on Console", typeof(IAmAliveSubscriber))] 8 | public class OnModuleIsAliveConsole : IAmAliveSubscriber 9 | { 10 | public void AmAlive(IModule item) 11 | { 12 | Console.WriteLine(item.GetType().Name); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /AppInfraDemo/UI/ConsoleApplication/OrdersConsoleApplication.cs: -------------------------------------------------------------------------------- 1 | using Contracts.Sales; 2 | 3 | namespace ConsoleApplication 4 | { 5 | class OrdersConsoleApplication 6 | { 7 | private readonly IConsole console; 8 | private readonly IOrderingService orderingService; 9 | 10 | public OrdersConsoleApplication(IConsole console, IOrderingService orderingService) 11 | { 12 | this.console = console; 13 | this.orderingService = orderingService; 14 | } 15 | 16 | 17 | public void ShowAllOrders() 18 | { 19 | console.WriteLine("OrdersConsole: Show all orders function"); 20 | string customerName = console.AskInput("Enter customer last name: "); 21 | 22 | SalesOrderInfo[] orders = orderingService.GetOrdersInfo(customerName); 23 | 24 | console.WriteLine($"Orders for customer {customerName}: "); //Test data: Abel | Smith | Adams 25 | foreach (SalesOrderInfo salesOrderInfo in orders) 26 | { 27 | console.WriteEntity(salesOrderInfo); 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /AppInfraDemo/UI/ConsoleApplication/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/WpfApplication/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/WpfApplication/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace WpfApplication 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/WpfApplication/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/WpfApplication/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace WpfApplication 4 | { 5 | /// 6 | /// Interaction logic for MainWindow.xaml 7 | /// 8 | public partial class MainWindow : Window 9 | { 10 | public MainWindow() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /AppInfraDemo/UI/WpfApplication/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WpfApplication.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.2.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/WpfApplication/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /AppInfraDemo/UI/WpfApplication/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /AppInfraDemo/_App_Data/readme.md: -------------------------------------------------------------------------------- 1 | Use this folder when you want to use the AdventureWorks2012 database from the local SQL Express. 2 | ----------------- 3 | 4 | The `AppInfraDemo\_App_Data` folder should contain the `AdventureWorks2012.mdf` in order to be attached to the local database on the application start. 5 | 6 | To configure this follow these steps: 7 | 1. Download the `AdventureWorks2012.mdf` from [https://1drv.ms/u/s!AttpJoJRCtSQiiG8WJT8t3C4y450](https://1drv.ms/u/s!AttpJoJRCtSQiiG8WJT8t3C4y450) 8 | 2. Copy it to `AppInfraDemo\_App_Data` folder 9 | 3. Make sure that your host app sets the |DataDirectory| on the AppDomain 10 | - see `AppInfraDemo\UI\ConsoleApplication\Program.SetupDataDirectory()` 11 | 4. Set the connection string that uses `AttachDbFilename` setting 12 | - see `AppInfraDemo\UI\ConsoleApplication\App.config` 13 | - ex: `data source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\AdventureWorks2012.mdf;initial catalog=AdventureWorks2012;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework` 14 | - make sure that the `AdventureWorks2012.mdf` file name matches the one in the connection string 15 | 16 | More about AdventureWorks sample databases [here](https://learn.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver16&tabs=ssms). -------------------------------------------------------------------------------- /DesignPatterns/CodeDesign-DesignPatterns.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDemo", "ConsoleDemo\ConsoleDemo.csproj", "{D2F71473-27B8-4A87-A248-4919A8E62F61}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D2F71473-27B8-4A87-A248-4919A8E62F61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D2F71473-27B8-4A87-A248-4919A8E62F61}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D2F71473-27B8-4A87-A248-4919A8E62F61}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D2F71473-27B8-4A87-A248-4919A8E62F61}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/AbstractFactory/AnimalWorld.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.AbstractFactory 2 | { 3 | /// 4 | /// The 'Client' class 5 | /// 6 | class AnimalWorld 7 | { 8 | private readonly Herbivore _herbivore; 9 | private readonly Carnivore _carnivore; 10 | 11 | // Constructor 12 | public AnimalWorld(ContinentFactory factory) 13 | { 14 | _carnivore = factory.CreateCarnivore(); 15 | _herbivore = factory.CreateHerbivore(); 16 | } 17 | 18 | public void RunFoodChain() 19 | { 20 | _carnivore.Eat(_herbivore); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/AbstractFactory/ScrollBar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.AbstractFactory 4 | { 5 | class MacScrollBar : IScrollBar 6 | { 7 | public void ScrollUp(int points) 8 | { 9 | Console.WriteLine("Mac scrolling up"); 10 | } 11 | 12 | public void ScrollDown(int points) 13 | { 14 | Console.WriteLine("Mac scrolling down"); 15 | } 16 | } 17 | 18 | class WinScrollBar : IScrollBar 19 | { 20 | public void ScrollUp(int points) 21 | { 22 | Console.WriteLine("Win scrolling up"); 23 | } 24 | 25 | public void ScrollDown(int points) 26 | { 27 | Console.WriteLine("Win scrolling down"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/AbstractFactory/WidgetsClientApp.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.AbstractFactory 2 | { 3 | public class WidgetsClientApp 4 | { 5 | private readonly IWidgetFactory factory; 6 | 7 | public WidgetsClientApp(IWidgetFactory factory) 8 | { 9 | this.factory = factory; 10 | } 11 | 12 | public void Run() 13 | { 14 | IWindow window = factory.CreateWidget(); 15 | IScrollBar scrollBar = factory.CreateWidget(); 16 | 17 | window.SetScrollbars(scrollBar, scrollBar); 18 | window.Open(); 19 | window.VerticalScrollBar.ScrollDown(10); 20 | 21 | window.Close(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/ChainOfResponsibility/021_RequestHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.ChainOfResponsibility 4 | { 5 | interface IRequestHandler 6 | { 7 | int Handle(Request request); 8 | 9 | IRequestHandler Successor { get; set; } 10 | } 11 | 12 | abstract class RequestHandler : IRequestHandler 13 | { 14 | public int Handle(Request request) 15 | { 16 | if (CanHandle(request)) 17 | return HandleInternal(request); 18 | 19 | if (Successor !=null) 20 | { 21 | return Successor.Handle(request); 22 | } 23 | 24 | throw new InvalidOperationException("This handler cannot handle this request"); 25 | } 26 | 27 | protected abstract bool CanHandle(Request request); 28 | protected abstract int HandleInternal(Request request); 29 | 30 | public IRequestHandler Successor { get; set; } 31 | 32 | 33 | protected bool FileExists(string fileName) 34 | { 35 | // ... real implementation here ... 36 | return false; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/ChainOfResponsibility/023_FileManager2.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.ChainOfResponsibility 2 | { 3 | class FileManager2 4 | { 5 | private readonly IRequestHandler handler; 6 | 7 | public FileManager2 () 8 | { 9 | handler = new CreateNew 10 | { 11 | Successor = new FileExistsAndOverwriteNotRequested 12 | { 13 | Successor = new OverwriteWithNewFormat 14 | { 15 | Successor = new OverwriteWithSameFormat 16 | { 17 | Successor = new CannotOverwrite() 18 | } 19 | } 20 | } 21 | }; 22 | } 23 | 24 | public int CreateFile(Request createFileRequest) 25 | { 26 | return handler.Handle(createFileRequest); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/ChainOfResponsibility/PurchaseOrder.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.ChainOfResponsibility 2 | { 3 | public class PurchaseOrder 4 | { 5 | public PurchaseOrder(int number, double amount, string assets) 6 | { 7 | Number = number; 8 | Amount = amount; 9 | Assets = assets; 10 | } 11 | 12 | public int Number { get; set; } 13 | public double Amount { get; set; } 14 | public string Assets { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Composite/01_IGraphicElement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Composite.Transparency 4 | { 5 | public interface IGraphicElement 6 | { 7 | void Draw(int leftMargin); 8 | string Name { get; set; } 9 | 10 | int Order { get; set; } 11 | IGraphicElement Parent { get; set; } 12 | 13 | void Add(IGraphicElement childElement); 14 | void Remove(IGraphicElement element); 15 | IEnumerable GetChildElements(); 16 | } 17 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Composite/11_GraphicElement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Composite.Safety 4 | { 5 | public interface IGraphicElement 6 | { 7 | void Draw(int leftMargin); 8 | string Name { get; set; } 9 | 10 | int Order { get; set; } 11 | IGraphicElement Parent { get; set; } 12 | } 13 | 14 | public interface IGraphicElementContainer : IGraphicElement 15 | { 16 | void Add(IGraphicElement childElement); 17 | void Remove(IGraphicElement element); 18 | IEnumerable GetChildElements(); 19 | } 20 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Composite/Extension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ConsoleDemo.Composite.Transparency 5 | { 6 | internal static class DisplayExtension 7 | { 8 | public static void Display(this string text, int margin) 9 | { 10 | Console.WriteLine(new string(' ', margin*2) + text); 11 | } 12 | } 13 | 14 | internal static class GraphicElementExtensions 15 | { 16 | public static void Draw(this IGraphicElement graphic) 17 | { 18 | graphic.Draw(0); 19 | } 20 | 21 | public static void Draw(this IGraphicElement[] drawing) 22 | { 23 | foreach (var graphicElement in drawing) 24 | { 25 | graphicElement.Draw(); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Composite/Extension1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Composite.Safety 4 | { 5 | static class DisplayExtension 6 | { 7 | public static void Display(this string text, int margin) 8 | { 9 | Console.WriteLine(new string(' ', margin*2) + text); 10 | } 11 | } 12 | 13 | static class GraphicElementExtensions 14 | { 15 | public static void Draw(this IGraphicElement graphic) 16 | { 17 | graphic.Draw(0); 18 | } 19 | 20 | public static void Draw(this IGraphicElement[] drawing) 21 | { 22 | foreach (var graphicElement in drawing) 23 | { 24 | graphicElement.Draw(); 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Decorator/02_ScrollBarWindow.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Decorator 2 | { 3 | class ScrollBarWindow : WindowDecorator 4 | { 5 | private readonly IWindow scrollBarWindow; 6 | 7 | public ScrollBarWindow(IWindow decorated) 8 | : base(decorated) 9 | { 10 | var horizontalScrollBarWindow = new HorizontalScrollBarWindow(decorated); 11 | scrollBarWindow = new VerticalScrollBarWindow(horizontalScrollBarWindow); 12 | } 13 | 14 | public override void Draw() 15 | { 16 | scrollBarWindow.Draw(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Decorator/_Client.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Decorator 4 | { 5 | public static class DecoratorClient 6 | { 7 | public static void Run() 8 | { 9 | var simpleWindow = new Window(); 10 | var verticalScrollWindow = new VerticalScrollBarWindow(simpleWindow); 11 | var scrollWindow = new HorizontalScrollBarWindow(verticalScrollWindow); 12 | 13 | scrollWindow.Draw(); 14 | Console.WriteLine(); 15 | 16 | Console.WriteLine("--------------------------------------------------------------------"); 17 | ScrollBarWindow scrollBarWindow = new ScrollBarWindow(simpleWindow); 18 | scrollBarWindow.Draw(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ConsoleDemo.AbstractFactory; 3 | using ConsoleDemo.ChainOfResponsibility; 4 | using ConsoleDemo.Decorator; 5 | using ConsoleDemo.Strategy; 6 | using ConsoleDemo.Visitor.v3; 7 | using ConsoleDemo.Visitor.v5; 8 | using ConsoleDemo.Visitor.v6; 9 | 10 | namespace ConsoleDemo 11 | { 12 | public static class Program 13 | { 14 | public static void Main() 15 | { 16 | AnimalWorldDemo.Run(); 17 | //WidgetsDemo.Run(); 18 | 19 | //DecoratorClient.Run(); 20 | 21 | //Composite.Transparency.CompositeClient.Demo(); 22 | //Composite.Safety.CompositeClient.Demo(); 23 | 24 | //StrategyClient.RobotsDemo(); 25 | 26 | //ChainOfResponsibilityClient.PurchaseOrderApproverDemo(); 27 | 28 | 29 | //VisitorDemo5.Run(); 30 | //VisitorDemo6.Run(); 31 | 32 | 33 | // Wait for user input 34 | Console.ReadLine(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Strategy/04_GenericRobot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Strategy 4 | { 5 | public class GenericRobot 6 | where TBehavior : IBehaviour, new() 7 | { 8 | private readonly IBehaviour behaviour; 9 | private String name; 10 | 11 | public GenericRobot(String name) 12 | { 13 | this.name = name; 14 | behaviour = new TBehavior(); 15 | } 16 | 17 | public IBehaviour Behaviour 18 | { 19 | get { return behaviour; } 20 | } 21 | 22 | public void Move() 23 | { 24 | Console.WriteLine(this.name + ": Based on current position " + 25 | "the behavior decides the next Move:"); 26 | int command = behaviour.Move(); 27 | } 28 | 29 | public string Name 30 | { 31 | get { return name; } 32 | set { this.name = value; } 33 | } 34 | } 35 | 36 | // the client does not need to know about the behaviors. It can directly use the AgressiveRobot 37 | public class AggressiveRobot : GenericRobot 38 | { 39 | public AggressiveRobot(string name) 40 | : base(name) 41 | { 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Strategy/Coordonates.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Strategy 2 | { 3 | public struct Configuration 4 | { 5 | public Coordonates Natural; 6 | public Coordonates Stretchability; 7 | public Coordonates Shrinkability ; 8 | } 9 | 10 | public class Coordonates 11 | { 12 | } 13 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Strategy/ITextWrappingStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Strategy 4 | { 5 | public interface ITextWrappingStrategy 6 | { 7 | PageRow Format(IEnumerable componentsStream); 8 | } 9 | 10 | class InlineStrategy : ITextWrappingStrategy 11 | { 12 | public PageRow Format(IEnumerable componentsStream) 13 | { 14 | throw new System.NotImplementedException(); 15 | } 16 | } 17 | 18 | class TightStrategy : ITextWrappingStrategy 19 | { 20 | public PageRow Format(IEnumerable componentsStream) 21 | { 22 | throw new System.NotImplementedException(); 23 | } 24 | } 25 | 26 | class CenterStrategy : ITextWrappingStrategy 27 | { 28 | public PageRow Format(IEnumerable componentsStream) 29 | { 30 | throw new System.NotImplementedException(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Strategy/_RobotsClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Strategy 4 | { 5 | public class StrategyClient 6 | { 7 | public static void RobotsDemo() 8 | { 9 | Robot bigRobot = new Robot("Big Robot"); 10 | Robot george = new Robot("George v.2.1"); 11 | Robot r2 = new Robot("R2"); 12 | 13 | bigRobot.Behaviour = new AgressiveBehaviour(); 14 | george.Behaviour = new DefensiveBehaviour(); 15 | r2.Behaviour = new NormalBehaviour(); 16 | 17 | bigRobot.Move(); 18 | george.Move(); 19 | r2.Move(); 20 | 21 | Console.WriteLine("\r\n Base on current context, new behaviors: " + 22 | "\r\n\t'Big Robot' gets really scared" + 23 | "\r\n\t, 'George v.2.1' becomes really mad because" + 24 | "it's always attacked by other robots" + 25 | "\r\n\t and R2 keeps its calm\r\n"); 26 | 27 | bigRobot.Behaviour = new DefensiveBehaviour(); 28 | george.Behaviour = new AgressiveBehaviour(); 29 | 30 | bigRobot.Move(); 31 | george.Move(); 32 | r2.Move(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/.readme.html: -------------------------------------------------------------------------------- 1 | 

Sample Description

2 |

This folder contains an evolution of the same sample from v1 to v5 showing from version to version ow same implementation can gradually be improved with the Visitor pattern (v3) towards better implementations of the same pattern

3 |

Versions:

4 |
    5 |
  • v0 - just sets the stage
  • 6 |
  • v1 - each operation is done in the client with if/else if
  • 7 |
  • v2 - each operation is implemented in every element. 8 |
      9 |
    • downsides: 10 |
        11 |
      • mixture of concerns in same class (element)
      • 12 |
      • had to add new operations
      • 13 |
      14 |
    • 15 |
    16 |
  • 17 |
  • v3 - by the book implementation of the Visitor pattern
  • 18 |
  • v4 - a better implementation of the Visitor pattern, where the client code links the general visitor and the specific one
  • 19 |
20 |
 Report report = new Report();
21 |  IVisitor reportVisitor = new Visitor(report);
22 | 
23 |
    24 |
  • v5 - an improvement by making the link between IVisitor and IVisitor<TElement> visible in the interfaces, but making the specific visitor implementations a bit more complex.
  • 25 |
26 | -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/.readme.md: -------------------------------------------------------------------------------- 1 | Sample Description 2 | ========== 3 | 4 | This folder contains an evolution of the same sample from v1 to v5 showing from version to version how the same implementation can gradually be improved with the Visitor pattern (v3) towards better implementations of the same pattern 5 | 6 | Versions: 7 | - v0 - just sets the stage 8 | - v1 - each operation is done in the client with `if/else if` 9 | - v2 - each operation is implemented in every element. 10 | - downsides: 11 | - mixture of concerns in same class (element) 12 | - had to add new operations 13 | - v3 - by the book implementation of the Visitor pattern 14 | - v4 - a better implementation of the Visitor pattern, where the client code links the general visitor and the specific one 15 | ``` 16 | Report report = new Report(); 17 | IVisitor reportVisitor = new Visitor(report); 18 | ``` 19 | 20 | - v5 - an improvement by making the link between `IVisitor` and `IVisitor` visible in the interfaces, but making the specific visitor implementations a bit more complex. 21 | -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/ICrmService.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor 2 | { 3 | internal interface ICrmService 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor 4 | { 5 | internal interface IUnitOfWork : IDisposable 6 | { 7 | void Add(object entity); 8 | void SaveChanges(); 9 | } 10 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/OrderLine.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor 2 | { 3 | public class OrderLine 4 | { 5 | public Product Product { get; set; } 6 | public int Quantity { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/Product.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor 2 | { 3 | public class Product 4 | { 5 | public string Name { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/UofFactory.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor 2 | { 3 | internal class UofFactory 4 | { 5 | public static IUnitOfWork CreateUnitOfWork() 6 | { 7 | throw new System.NotImplementedException(); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v0/Commands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ConsoleDemo.Visitor.v0 5 | { 6 | class NewCustomerCommand 7 | { 8 | public string Name { get; set; } 9 | 10 | public string BusinessDomain { get; set; } 11 | } 12 | 13 | class NewPurchaseOrderCommand 14 | { 15 | public NewPurchaseOrderCommand(Product product, int i) 16 | { 17 | Product = product; 18 | } 19 | 20 | public Product Product { get; } 21 | 22 | public int Quantity { get; } 23 | } 24 | 25 | class NewSalesOrderCommand 26 | { 27 | public IEnumerable OrderLines { get; } 28 | 29 | public string CustomerCode { get; set; } 30 | 31 | public DateTime Date { get; set; } 32 | } 33 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v0/CommandsManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Visitor.v0 4 | { 5 | public class CommandsManager 6 | { 7 | readonly List items = new List(); 8 | 9 | // The client class has a structure (a list in this case) of items (commands). 10 | // The client knows how to iterate through the structure 11 | // The client would need to do different operations on the items from the structure when iterating it 12 | } 13 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v1/Command.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ConsoleDemo.Visitor.v1 5 | { 6 | 7 | class NewPurchaseOrderCommand 8 | { 9 | public NewPurchaseOrderCommand(Product product) 10 | { 11 | Product = product; 12 | } 13 | 14 | public Product Product { get; } 15 | 16 | public int Quantity { get; } 17 | } 18 | 19 | class NewSalesOrderCommand 20 | { 21 | public IEnumerable OrderLines { get; } 22 | 23 | public string CustomerCode { get; set; } 24 | 25 | public DateTime Date { get; set; } 26 | } 27 | 28 | class NewCustomerCommand 29 | { 30 | public string Name { get; set; } 31 | 32 | public string BusinessDomain { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v2/Client.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Visitor.v2 4 | { 5 | public class CommandsManager 6 | { 7 | readonly List requests = new List(); 8 | 9 | public void ApproveAll() 10 | { 11 | foreach (var item in requests) 12 | { 13 | item.Approve(); 14 | } 15 | } 16 | 17 | public void PrettyPrint() 18 | { 19 | foreach (var item in requests) 20 | { 21 | item.PrettyPrint(); 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/Client.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Visitor.v3 4 | { 5 | public class CommandsManager 6 | { 7 | private readonly List items = new List(); 8 | 9 | public CommandsManager() 10 | { 11 | this.items.AddRange(DemoData.GetItems()); 12 | } 13 | 14 | public void PrettyPrint() 15 | { 16 | ReportVisitor report = new ReportVisitor(); 17 | foreach (var item in items) 18 | { 19 | item.Accept(report); 20 | } 21 | 22 | report.Print(); 23 | } 24 | 25 | public void ApproveAll() 26 | { 27 | IVisitor[] visitors = GetApproveVisitors(); 28 | foreach (var item in items) 29 | { 30 | foreach (var visitor in visitors) 31 | { 32 | item.Accept(visitor); 33 | } 34 | } 35 | } 36 | 37 | private IVisitor[] GetApproveVisitors() 38 | { 39 | return new IVisitor[] 40 | { 41 | new NewCustomerCommandApprover(), 42 | new PurchaseOrderCommandApprover(), 43 | new SalesOrderCommandApprover() 44 | }; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/CommandsRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Visitor.v3 4 | { 5 | class CommandsRepository : IVisitor 6 | { 7 | readonly List toSave = new List(); 8 | 9 | public void SaveChanges() 10 | { 11 | using (IUnitOfWork uof = UofFactory.CreateUnitOfWork()) 12 | { 13 | foreach (var entity in toSave) 14 | { 15 | uof.Add(entity); 16 | } 17 | 18 | uof.SaveChanges(); 19 | } 20 | toSave.Clear(); 21 | } 22 | 23 | public void VisitCustomerCommand(NewCustomerCommand customerCommand) 24 | { 25 | toSave.Add(customerCommand); 26 | } 27 | 28 | public void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 29 | { 30 | toSave.Add(salesOrderCommand); 31 | } 32 | 33 | public void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 34 | { 35 | toSave.Add(purchaseOrder); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/DemoData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v3 4 | { 5 | static class DemoData 6 | { 7 | public static IVisitable[] GetItems() 8 | { 9 | return new IVisitable[] 10 | { 11 | new NewPurchaseOrderCommand(new Product {Name = "iPhone"}, 5), 12 | new NewPurchaseOrderCommand(new Product {Name = "MacBookPro"}, 7), 13 | new NewPurchaseOrderCommand(new Product {Name = "MacBookAir"}, 1), 14 | 15 | new NewSalesOrderCommand("Apple", DateTime.Today).AddOrderLine("AwesomeApp v2", 2), 16 | new NewSalesOrderCommand("Microsoft", DateTime.Today).AddOrderLine("AwesomeApp v1", 1), 17 | 18 | new NewCustomerCommand("Deep Mind", "Computers") 19 | }; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/IVisitable.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v3 2 | { 3 | public interface IVisitable 4 | { 5 | void Accept(IVisitor visitor); 6 | } 7 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/IVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v3 2 | { 3 | public interface IVisitor 4 | { 5 | void VisitCustomerCommand(NewCustomerCommand customerCommand); 6 | void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand); 7 | void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder); 8 | } 9 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/NewCustomerCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v3 4 | { 5 | class NewCustomerCommandApprover : IVisitor 6 | { 7 | private ICrmService crmService; 8 | 9 | public NewCustomerCommandApprover(ICrmService crmService) 10 | { 11 | this.crmService = crmService; 12 | } 13 | 14 | public void VisitCustomerCommand(NewCustomerCommand customerCommand) 15 | { 16 | Console.WriteLine($"We have new customer! {customerCommand.Name} welcome!"); 17 | } 18 | 19 | public void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 20 | { 21 | } 22 | 23 | public void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 24 | { 25 | } 26 | 27 | public NewCustomerCommandApprover() 28 | { 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/PurchaseOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v3 4 | { 5 | class PurchaseOrderCommandApprover : IVisitor 6 | { 7 | public void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 8 | { 9 | Console.WriteLine($"Purchase of: {purchaseOrder.Product.Name} was approved."); 10 | } 11 | 12 | public void VisitCustomerCommand(NewCustomerCommand customerCommand) 13 | { 14 | } 15 | 16 | public void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/ReportVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace ConsoleDemo.Visitor.v3 5 | { 6 | class ReportVisitor : IVisitor 7 | { 8 | readonly StringBuilder report = new StringBuilder(); 9 | 10 | public void Print() 11 | { 12 | Console.WriteLine(report); 13 | } 14 | 15 | public void VisitCustomerCommand(NewCustomerCommand customerCommand) 16 | { 17 | report.AppendLine($"New customer request: {customerCommand.Name} in business: {customerCommand.BusinessDomain}"); 18 | } 19 | 20 | public void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 21 | { 22 | report.AppendLine("Sales order request: "); 23 | foreach (var line in salesOrderCommand.OrderLines) 24 | { 25 | report.AppendLine($"\t Product={line.Product} Quantity={line.Quantity}"); 26 | } 27 | } 28 | 29 | public void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 30 | { 31 | report.AppendLine($"Purchase order request: Product={purchaseOrder.Product} Quatity={purchaseOrder.Quantity}"); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/SalesOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v3 4 | { 5 | class SalesOrderCommandApprover : IVisitor 6 | { 7 | public void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 8 | { 9 | Console.WriteLine($"Sales Order from {salesOrderCommand.CustomerCode} was approved."); 10 | } 11 | 12 | public void VisitCustomerCommand(NewCustomerCommand customerCommand) 13 | { 14 | } 15 | 16 | public void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v3/VisitorDemo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | 5 | namespace ConsoleDemo.Visitor.v3 6 | { 7 | public static class VisitorDemo3 8 | { 9 | public static void Run() 10 | { 11 | var client = new CommandsManager(); 12 | 13 | Console.WriteLine(); 14 | Console.WriteLine("PrettyPrint"); 15 | client.PrettyPrint(); 16 | 17 | Console.WriteLine(); 18 | Console.WriteLine("ApproveAll"); 19 | client.ApproveAll(); 20 | } 21 | 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/Client.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Visitor.v4 4 | { 5 | public class CommandsManager 6 | { 7 | private readonly List items = new List(); 8 | 9 | public CommandsManager() 10 | { 11 | this.items.AddRange(DemoData.GetItems()); 12 | } 13 | 14 | public void PrettyPrint() 15 | { 16 | ReportVisitor report = new ReportVisitor(); 17 | foreach (var item in items) 18 | { 19 | item.Accept(report); 20 | } 21 | 22 | report.Print(); 23 | } 24 | 25 | public void ApproveAll() 26 | { 27 | IVisitor[] visitors = GetApproveVisitors(); 28 | foreach (var item in items) 29 | { 30 | foreach (var visitor in visitors) 31 | { 32 | item.Accept(visitor); 33 | } 34 | } 35 | } 36 | 37 | private IVisitor[] GetApproveVisitors() 38 | { 39 | return new IVisitor[] 40 | { 41 | new NewCustomerCommandApprover(), 42 | new PurchaseOrderCommandApprover(), 43 | new SalesOrderCommandApprover() 44 | }; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/CommandsRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Visitor.v4 4 | { 5 | class CommandsRepository : Visitor 6 | { 7 | readonly List toSave = new List(); 8 | 9 | public void SaveChanges() 10 | { 11 | using (IUnitOfWork uof = UofFactory.CreateUnitOfWork()) 12 | { 13 | foreach (var entity in toSave) 14 | { 15 | uof.Add(entity); 16 | } 17 | 18 | uof.SaveChanges(); 19 | } 20 | toSave.Clear(); 21 | } 22 | 23 | public override void VisitCustomerCommand(NewCustomerCommand customerCommand) 24 | { 25 | toSave.Add(customerCommand); 26 | } 27 | 28 | public override void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 29 | { 30 | toSave.Add(salesOrderCommand); 31 | } 32 | 33 | public override void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 34 | { 35 | toSave.Add(purchaseOrder); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/DemoData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v4 4 | { 5 | static class DemoData 6 | { 7 | public static IVisitable[] GetItems() 8 | { 9 | return new IVisitable[] 10 | { 11 | new NewPurchaseOrderCommand(new Product {Name = "iPhone"}, 5), 12 | new NewPurchaseOrderCommand(new Product {Name = "MacBookPro"}, 7), 13 | new NewPurchaseOrderCommand(new Product {Name = "MacBookAir"}, 1), 14 | 15 | new NewSalesOrderCommand("Apple", DateTime.Today).AddOrderLine("AwesomeApp v2", 2), 16 | new NewSalesOrderCommand("Microsoft", DateTime.Today).AddOrderLine("AwesomeApp v1", 1), 17 | 18 | new NewCustomerCommand("Deep Mind", "Computers") 19 | }; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/IVisitable.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v4 2 | { 3 | public interface IVisitable 4 | { 5 | void Accept(IVisitor visitor); 6 | } 7 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/IVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v4 2 | { 3 | public interface IVisitor 4 | { 5 | void VisitCustomerCommand(NewCustomerCommand customerCommand); 6 | void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand); 7 | void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder); 8 | } 9 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/NewCustomerCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v4 4 | { 5 | class NewCustomerCommandApprover : Visitor 6 | { 7 | private ICrmService crmService; 8 | 9 | public NewCustomerCommandApprover(ICrmService crmService) 10 | { 11 | this.crmService = crmService; 12 | } 13 | 14 | public override void VisitCustomerCommand(NewCustomerCommand customerCommand) 15 | { 16 | Console.WriteLine($"We have new customer! {customerCommand.Name} welcome!"); 17 | } 18 | 19 | public NewCustomerCommandApprover() 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/PurchaseOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v4 4 | { 5 | class PurchaseOrderCommandApprover : Visitor 6 | { 7 | public override void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 8 | { 9 | Console.WriteLine($"Purchase of: {purchaseOrder.Product.Name} was approved."); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/ReportVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace ConsoleDemo.Visitor.v4 5 | { 6 | class ReportVisitor : Visitor 7 | { 8 | readonly StringBuilder report = new StringBuilder(); 9 | 10 | public void Print() 11 | { 12 | Console.WriteLine(report); 13 | } 14 | 15 | public override void VisitCustomerCommand(NewCustomerCommand customerCommand) 16 | { 17 | report.AppendLine($"New customer request: {customerCommand.Name} in business: {customerCommand.BusinessDomain}"); 18 | } 19 | 20 | public override void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 21 | { 22 | report.AppendLine("Sales order request: "); 23 | foreach (var line in salesOrderCommand.OrderLines) 24 | { 25 | report.AppendLine($"\t Product={line.Product} Quantity={line.Quantity}"); 26 | } 27 | } 28 | 29 | public override void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 30 | { 31 | report.AppendLine($"Purchase order request: Product={purchaseOrder.Product} Quatity={purchaseOrder.Quantity}"); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/SalesOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v4 4 | { 5 | class SalesOrderCommandApprover : Visitor 6 | { 7 | public override void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 8 | { 9 | Console.WriteLine($"Sales Order from {salesOrderCommand.CustomerCode} was approved."); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/Visitor.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v4 2 | { 3 | abstract class Visitor : IVisitor 4 | { 5 | public virtual void VisitCustomerCommand(NewCustomerCommand customerCommand) 6 | { 7 | } 8 | 9 | public virtual void VisitSalesOrderCommand(NewSalesOrderCommand salesOrderCommand) 10 | { 11 | } 12 | 13 | public virtual void VisitPurchaseOrderCommand(NewPurchaseOrderCommand purchaseOrder) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v4/VisitorDemo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v4 4 | { 5 | public static class VisitorDemo3 6 | { 7 | public static void Run() 8 | { 9 | var client = new CommandsManager(); 10 | 11 | Console.WriteLine(); 12 | Console.WriteLine("PrettyPrint"); 13 | client.PrettyPrint(); 14 | 15 | Console.WriteLine(); 16 | Console.WriteLine("ApproveAll"); 17 | client.ApproveAll(); 18 | } 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/CommandsRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo.Visitor.v5 4 | { 5 | class CommandsRepository : IVisitor, 6 | IVisitor, 7 | IVisitor 8 | { 9 | readonly List toSave = new List(); 10 | 11 | public void SaveChanges() 12 | { 13 | using (IUnitOfWork uof = UofFactory.CreateUnitOfWork()) 14 | { 15 | foreach (var entity in toSave) 16 | { 17 | uof.Add(entity); 18 | } 19 | 20 | uof.SaveChanges(); 21 | } 22 | toSave.Clear(); 23 | } 24 | 25 | public void Visit(NewPurchaseOrderCommand element) 26 | { 27 | toSave.Add(element); 28 | } 29 | 30 | public void Visit(NewSalesOrderCommand element) 31 | { 32 | toSave.Add(element); 33 | } 34 | 35 | public void Visit(NewCustomerCommand element) 36 | { 37 | toSave.Add(element); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/DemoData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v5 4 | { 5 | static class DemoData 6 | { 7 | public static IVisitable[] GetItems() 8 | { 9 | return new IVisitable[] 10 | { 11 | new NewPurchaseOrderCommand(new Product {Name = "iPhone"}, 5), 12 | new NewPurchaseOrderCommand(new Product {Name = "MacBookPro"}, 7), 13 | new NewPurchaseOrderCommand(new Product {Name = "MacBookAir"}, 1), 14 | 15 | new NewSalesOrderCommand("Apple", DateTime.Today).AddOrderLine("AwesomeApp v2", 2), 16 | new NewSalesOrderCommand("Microsoft", DateTime.Today).AddOrderLine("AwesomeApp v1", 1), 17 | 18 | new NewCustomerCommand("Deep Mind", "Computers") 19 | }; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/IVisitable.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v5 2 | { 3 | public interface IVisitable 4 | { 5 | void Accept(IVisitor visitor); 6 | } 7 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/IVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v5 2 | { 3 | public interface IVisitor 4 | { 5 | void Visit(TElement element); 6 | } 7 | 8 | public interface IVisitor 9 | { 10 | void Visit(TElement element); 11 | } 12 | 13 | 14 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/NewCustomerCommandApporver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v5 4 | { 5 | class NewCustomerCommandApporver : IVisitor 6 | { 7 | public void Visit(NewCustomerCommand customerCommand) 8 | { 9 | Console.WriteLine($"We have new customer! {customerCommand.Name} welcome!"); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/PurchaseOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v5 4 | { 5 | class PurchaseOrderCommandApprover : IVisitor 6 | { 7 | public void Visit(NewPurchaseOrderCommand purchaseOrder) 8 | { 9 | Console.WriteLine($"Purchase of: {purchaseOrder.Product.Name} was approved."); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/Report.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace ConsoleDemo.Visitor.v4 5 | { 6 | class Report : 7 | IVisitor, 8 | IVisitor, 9 | IVisitor 10 | { 11 | readonly StringBuilder report = new StringBuilder(); 12 | 13 | public void Print() 14 | { 15 | Console.WriteLine(report); 16 | } 17 | 18 | public void Visit(NewCustomerCommand customerCommand) 19 | { 20 | report.AppendLine($"New customer request: {customerCommand.Name} in business: {customerCommand.BusinessDomain}"); 21 | } 22 | 23 | public void Visit(NewSalesOrderCommand salesOrderCommand) 24 | { 25 | report.AppendLine("Sales order request: "); 26 | foreach (var line in salesOrderCommand.OrderLines) 27 | { 28 | report.AppendLine($"\t Product={line.Product} Quantity={line.Quantity}"); 29 | } 30 | } 31 | 32 | public void Visit(NewPurchaseOrderCommand purchaseOrder) 33 | { 34 | report.AppendLine($"Purchase order request: Product={purchaseOrder.Product} Quatity={purchaseOrder.Quantity}"); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/ReportVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace ConsoleDemo.Visitor.v5 5 | { 6 | class Report : IVisitor, 7 | IVisitor, 8 | IVisitor 9 | { 10 | readonly StringBuilder report = new StringBuilder(); 11 | 12 | public void Print() 13 | { 14 | Console.WriteLine(report); 15 | } 16 | 17 | public void Visit(NewCustomerCommand customerCommand) 18 | { 19 | report.AppendLine($"New customer request: {customerCommand.Name} in business: {customerCommand.BusinessDomain}"); 20 | } 21 | 22 | public void Visit(NewSalesOrderCommand salesOrderCommand) 23 | { 24 | report.AppendLine("Sales order request: "); 25 | foreach (var line in salesOrderCommand.OrderLines) 26 | { 27 | report.AppendLine($"\t - Product={line.Product} Quantity={line.Quantity}"); 28 | } 29 | } 30 | 31 | public void Visit(NewPurchaseOrderCommand purchaseOrder) 32 | { 33 | report.AppendLine($"Purchase order request: Product={purchaseOrder.Product} Quantity={purchaseOrder.Quantity}"); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/SalesOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v5 4 | { 5 | class SalesOrderCommandApprover : IVisitor 6 | { 7 | public void Visit(NewSalesOrderCommand salesOrderCommand) 8 | { 9 | Console.WriteLine($"Sales Order from {salesOrderCommand.CustomerCode} was approved."); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/Visitor.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v5 2 | { 3 | sealed class Visitor : IVisitor 4 | { 5 | private readonly object specificVisitor; 6 | 7 | public Visitor(object specificVisitor) 8 | { 9 | this.specificVisitor = specificVisitor; 10 | } 11 | 12 | public void Visit(TElement element) 13 | { 14 | IVisitor visitor = specificVisitor as IVisitor; 15 | visitor?.Visit(element); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v5/VisitorDemo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v5 4 | { 5 | public static class VisitorDemo5 6 | { 7 | public static void Run() 8 | { 9 | var client = new CommandsManager(); 10 | 11 | Console.WriteLine(); 12 | Console.WriteLine("PrettyPrint"); 13 | client.PrettyPrint(); 14 | 15 | Console.WriteLine(); 16 | Console.WriteLine("ApproveAll"); 17 | client.ApproveAll(); 18 | } 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/DemoData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v6 4 | { 5 | static class DemoData 6 | { 7 | public static IVisitable[] GetItems() 8 | { 9 | return new IVisitable[] 10 | { 11 | new NewPurchaseOrderCommand(new Product {Name = "iPhone"}, 5), 12 | new NewPurchaseOrderCommand(new Product {Name = "MacBookPro"}, 7), 13 | new NewPurchaseOrderCommand(new Product {Name = "MacBookAir"}, 1), 14 | 15 | new NewSalesOrderCommand("Apple", DateTime.Today).AddOrderLine("AwesomeApp v2", 2), 16 | new NewSalesOrderCommand("Microsoft", DateTime.Today).AddOrderLine("AwesomeApp v1", 1), 17 | 18 | new NewCustomerCommand("Deep Mind", "Computers") 19 | }; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/IVisitable.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v6 2 | { 3 | public interface IVisitable 4 | { 5 | void Accept(IVisitor visitor); 6 | } 7 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/IVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v6 2 | { 3 | public interface IVisitor 4 | { 5 | void Visit(TElement element); 6 | } 7 | 8 | public interface IVisitor 9 | { 10 | void Visit(TElement element); 11 | IVisitor AsVisitor(); 12 | } 13 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/NewCustomerCommandApporver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v6 4 | { 5 | class NewCustomerCommandApporver : IVisitor 6 | { 7 | private readonly IVisitor visitor; 8 | 9 | public NewCustomerCommandApporver() 10 | { 11 | visitor = new Visitor(this); 12 | } 13 | 14 | public void Visit(NewCustomerCommand customerCommand) 15 | { 16 | Console.WriteLine($"We have new customer! {customerCommand.Name} welcome!"); 17 | } 18 | 19 | public IVisitor AsVisitor() 20 | { 21 | return visitor; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/PurchaseOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v6 4 | { 5 | class PurchaseOrderCommandApprover : IVisitor 6 | { 7 | private readonly IVisitor visitor; 8 | 9 | public PurchaseOrderCommandApprover() 10 | { 11 | visitor = new Visitor(this); 12 | } 13 | 14 | public void Visit(NewPurchaseOrderCommand purchaseOrder) 15 | { 16 | Console.WriteLine($"Purchase of: {purchaseOrder.Product.Name} was approved."); 17 | } 18 | 19 | public IVisitor AsVisitor() 20 | { 21 | return visitor; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/SalesOrderCommandApprover.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v6 4 | { 5 | class SalesOrderCommandApprover : IVisitor 6 | { 7 | private readonly IVisitor visitor; 8 | 9 | public SalesOrderCommandApprover() 10 | { 11 | visitor = new Visitor(this); 12 | } 13 | 14 | public void Visit(NewSalesOrderCommand salesOrderCommand) 15 | { 16 | Console.WriteLine($"Sales Order from {salesOrderCommand.CustomerCode} was approved."); 17 | } 18 | 19 | public IVisitor AsVisitor() 20 | { 21 | return visitor; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/Visitor.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleDemo.Visitor.v6 2 | { 3 | sealed class Visitor : IVisitor 4 | { 5 | private readonly object specificVisitor; 6 | 7 | public Visitor(object specificVisitor) 8 | { 9 | this.specificVisitor = specificVisitor; 10 | } 11 | 12 | public void Visit(TElement element) 13 | { 14 | IVisitor v = specificVisitor as IVisitor; 15 | v?.Visit(element); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /DesignPatterns/ConsoleDemo/Visitor/v6/VisitorDemo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConsoleDemo.Visitor.v6 4 | { 5 | public static class VisitorDemo6 6 | { 7 | public static void Run() 8 | { 9 | var client = new CommandsManager(); 10 | 11 | Console.WriteLine(); 12 | Console.WriteLine("PrettyPrint"); 13 | client.PrettyPrint(); 14 | 15 | Console.WriteLine(); 16 | Console.WriteLine("ApproveAll"); 17 | client.ApproveAll(); 18 | } 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/.Notes/md-template.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | [title] 8 | 9 | 10 |
11 | [content] 12 |
13 | 14 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/AppBootEx/ServiceProxyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using iQuarc.AppBoot; 3 | 4 | namespace AppBootEx 5 | { 6 | [AttributeUsage(AttributeTargets.Class)] 7 | public sealed class ServiceProxyAttribute : Attribute 8 | { 9 | public ServiceProxyAttribute(Type exportType) 10 | { 11 | ExportType = exportType; 12 | } 13 | 14 | public Type ExportType { get; private set; } 15 | } 16 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/AppBootEx/ServiceProxyRegistrationBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using iQuarc.AppBoot; 5 | using iQuarc.SystemEx; 6 | 7 | namespace AppBootEx 8 | { 9 | public sealed class ServiceProxyRegistrationBehavior : IRegistrationBehavior 10 | { 11 | public IEnumerable GetServicesFrom(Type type) 12 | { 13 | IEnumerable attributes = type.GetAttributes(false); 14 | return attributes.Select(a => new ServiceInfo(a.ExportType, type, null, Lifetime.AlwaysNew)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/ConsoleHost.portfolio.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/ConsoleHost.quotation.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/ConsoleHost.sales.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/Deploy-HostAll.bat: -------------------------------------------------------------------------------- 1 | cd %1 2 | 3 | del ..\..\Deploy\HostAll\*.* /F /Q 4 | 5 | xcopy ..\*.dll ..\..\Deploy\HostAll\ /Y /I 6 | xcopy ..\ConsoleHost.exe* ..\..\Deploy\HostAll -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/Deploy-HostEach.bat: -------------------------------------------------------------------------------- 1 | cd %1 2 | 3 | call .\Deploy-HostPortfolio.bat 4 | call .\Deploy-HostQuotation.bat 5 | call .\Deploy-HostSales.bat 6 | 7 | copy startAll.bat ..\..\Deploy -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/Deploy-HostPortfolio.bat: -------------------------------------------------------------------------------- 1 | cd %1 2 | 3 | del ..\..\Deploy\Portfolio\*.* /F /Q 4 | 5 | xcopy ..\*.dll ..\..\Deploy\Portfolio\ /Y /I 6 | xcopy ..\ConsoleHost.exe ..\..\Deploy\Portfolio 7 | xcopy ConsoleHost.Portfolio.config ..\..\Deploy\Portfolio 8 | rename ..\..\Deploy\Portfolio\ConsoleHost.portfolio.config ConsoleHost.exe.config 9 | 10 | del ..\..\Deploy\Portfolio\Quotations.* /F /Q 11 | del ..\..\Deploy\Portfolio\Sales.* /F /Q -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/Deploy-HostQuotation.bat: -------------------------------------------------------------------------------- 1 | cd %1 2 | 3 | del ..\..\Deploy\Quotation\*.* /F /Q 4 | 5 | xcopy ..\*.dll ..\..\Deploy\Quotation\ /Y /I 6 | xcopy ..\ConsoleHost.exe ..\..\Deploy\Quotation 7 | xcopy ConsoleHost.Quotation.config ..\..\Deploy\Quotation 8 | rename ..\..\Deploy\Quotation\ConsoleHost.quotation.config ConsoleHost.exe.config 9 | 10 | del ..\..\Deploy\Quotation\Portfolio.* /F /Q 11 | del ..\..\Deploy\Quotation\Sales.* /F /Q -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/Deploy-HostSales.bat: -------------------------------------------------------------------------------- 1 | cd %1 2 | 3 | del ..\..\Deploy\Sales\*.* /F /Q 4 | 5 | xcopy ..\*.dll ..\..\Deploy\Sales\ /Y /I 6 | xcopy ..\ConsoleHost.exe ..\..\Deploy\Sales 7 | xcopy ConsoleHost.Sales.config ..\..\Deploy\Sales 8 | rename ..\..\Deploy\Sales\ConsoleHost.sales.config ConsoleHost.exe.config 9 | 10 | del ..\..\Deploy\Sales\Quotations.* /F /Q 11 | del ..\..\Deploy\Sales\Portfolio.* /F /Q -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/.Deployment/startAll.bat: -------------------------------------------------------------------------------- 1 | start .\Portfolio\ConsoleHost.exe 2 | 3 | start .\Quotation\ConsoleHost.exe 4 | 5 | start .\Sales\ConsoleHost.exe -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/Controllers/OrdersController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Web.Http; 5 | using System.Web.Http.Results; 6 | using Contracts.Sales.Services; 7 | 8 | namespace ConsoleHost.Controllers 9 | { 10 | public class OrdersController : ApiController 11 | { 12 | private readonly IOrdersService ordersService; 13 | 14 | public OrdersController(IOrdersService ordersService) 15 | { 16 | this.ordersService = ordersService; 17 | } 18 | 19 | public IHttpActionResult PlaceSellLimitOrder(string securityCode, decimal sellingPrice, DateTime validUntil) 20 | { 21 | ordersService.PlaceSellLimitOrder(securityCode, sellingPrice, validUntil); 22 | return Ok(); 23 | } 24 | 25 | public IHttpActionResult PlaceBuyLimitOrder(string securityCode, decimal buyingPrice, DateTime validUntil) 26 | { 27 | ordersService.PlaceBuyLimitOrder(securityCode, buyingPrice, validUntil); 28 | return Ok(); 29 | } 30 | 31 | public IEnumerable GetLimitOrders() 32 | { 33 | return ordersService.GetLimitOrders(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/Controllers/PortfolioController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using Contracts.Portfolio.Services; 3 | 4 | namespace ConsoleHost.Controllers 5 | { 6 | public class PortfolioController : ApiController 7 | { 8 | private readonly IPortfolioService portfolioService; 9 | 10 | public PortfolioController(IPortfolioService portfolioService) 11 | { 12 | this.portfolioService = portfolioService; 13 | } 14 | 15 | public decimal GetValue() 16 | { 17 | return portfolioService.GetPortfolioValue(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/Controllers/QuotationController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Web.Http; 4 | using Contracts.Quotations.Services; 5 | 6 | namespace ConsoleHost.Controllers 7 | { 8 | public class QuotationController : ApiController 9 | { 10 | private readonly IQuotationService quotationService; 11 | public QuotationController(IQuotationService quotationService) 12 | { 13 | this.quotationService = quotationService; 14 | } 15 | 16 | public IEnumerable GetByExchange(string exchange, string instrument, DateTime @from, DateTime to) 17 | { 18 | return quotationService.GetQuotations(exchange, instrument, from, to); 19 | } 20 | 21 | public IEnumerable GetBySecurity([FromUri] string securityCode, [FromUri] DateTime from, [FromUri] DateTime to) 22 | { 23 | return quotationService.GetQuotations(securityCode, from, to); 24 | } 25 | 26 | public IEnumerable GetBySecurities([FromUri] string[] securities, [FromUri] DateTime from, [FromUri] DateTime to) 27 | { 28 | return quotationService.GetQuotations(securities, from, to); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleHost/Startup.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using ConsoleHost.Filters; 3 | using iQuarc.AppBoot.WebApi; 4 | using Owin; 5 | 6 | namespace ConsoleHost 7 | { 8 | public class Startup 9 | { 10 | // This code configures Web API. The Startup class is specified as a type 11 | // parameter in the WebApp.Start method. 12 | public void Configuration(IAppBuilder appBuilder) 13 | { 14 | // Configure Web API for self-host. 15 | HttpConfiguration config = new HttpConfiguration(); 16 | config.Routes.MapHttpRoute( 17 | name: "DefaultApi", 18 | routeTemplate: "api/{controller}/{action}" 19 | ); 20 | 21 | AppBootBootstrapper.Run().ConfigureWebApi(config); 22 | 23 | config.Filters.Add(new ConsoleLogFilter()); 24 | 25 | appBuilder.UseWebApi(config); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleUi/.Deployment/Deploy-ConsoleUi-ProxyOnly.bat: -------------------------------------------------------------------------------- 1 | cd %1 2 | 3 | del ..\..\Deploy\ConsoleUi\*.* /F /Q 4 | 5 | xcopy ..\*.dll ..\..\Deploy\ConsoleUi\ /Y /I 6 | xcopy ..\ConsoleUi.exe* ..\..\Deploy\ConsoleUi 7 | 8 | 9 | del ..\..\Deploy\ConsoleUi\Quotations.* /F /Q 10 | del ..\..\Deploy\ConsoleUi\Portfolio.* /F /Q 11 | del ..\..\Deploy\ConsoleUi\Sales.* /F /Q -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleUi/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/ConsoleUi/ConsoleEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using iQuarc.SystemEx; 3 | 4 | namespace ConsoleUi 5 | { 6 | class ConsoleEx 7 | { 8 | public static T AskInput(string message) 9 | { 10 | Console.WriteLine(); 11 | Console.WriteLine(message); 12 | 13 | string input = Console.ReadLine(); 14 | return ConvertExtensions.ChangeType(input); 15 | } 16 | 17 | public static void WriteEntity(T entity) 18 | { 19 | Console.WriteLine(); 20 | Console.WriteLine($"--------------- {typeof(T).Name} ----------------"); 21 | var properties = ReflectionExtensions.GetEditableSimpleProperties(entity); 22 | foreach (var propertyInfo in properties) 23 | { 24 | Console.Write($"{propertyInfo.Name}: "); 25 | Console.WriteLine(propertyInfo.GetValue(entity)); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Infrastructure/Common/Infra.Hosts/ModulesHostContainer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Contracts.Infrastructure; 3 | using iQuarc.AppBoot; 4 | 5 | namespace ConsoleHost 6 | { 7 | [Service(typeof(IModulesHostContainer), Lifetime.Application)] 8 | class ModulesHostContainer : IModulesHostContainer 9 | { 10 | private readonly List modules =new List(); 11 | 12 | public void RegisterModule(string moduleName) 13 | { 14 | modules.Add(moduleName); 15 | } 16 | 17 | public IEnumerable GetModules() 18 | { 19 | return modules; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Infrastructure/Proxies/PortfolioServiceProxy.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Web; 3 | using AppBootEx; 4 | using Contracts.Portfolio.Services; 5 | 6 | namespace Proxies 7 | { 8 | [ServiceProxy(typeof(IPortfolioService))] 9 | class PortfolioServiceProxy : IPortfolioService 10 | { 11 | public decimal GetPortfolioValue() 12 | { 13 | using (HttpClient client = HttpHelpers.CreateNewClient()) 14 | { 15 | string path = HttpHelpers.GetServicePath("GetValue"); 16 | HttpResponseMessage response = client.GetAsync(path).Result; 17 | if (response.IsSuccessStatusCode) 18 | { 19 | decimal value = response.Content.ReadAsAsync().Result; 20 | return value; 21 | } 22 | 23 | throw new HttpException((int)response.StatusCode, response.ReasonPhrase); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Infrastructure/Proxies/ProxiesModule.cs: -------------------------------------------------------------------------------- 1 | using Contracts.Infrastructure; 2 | using iQuarc.AppBoot; 3 | 4 | namespace Proxies 5 | { 6 | [Service(nameof(ProxiesModule), typeof(IModule))] 7 | class ProxiesModule : IModule 8 | { 9 | private readonly IModulesHostContainer container; 10 | 11 | public ProxiesModule(IModulesHostContainer container) 12 | { 13 | this.container = container; 14 | } 15 | 16 | public void Initialize() 17 | { 18 | container.RegisterModule($"Proxies Module ID: {HttpHelpers.ClientId}"); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Infrastructure/Proxies/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/MigrationBackup/00c682d4/Infrastructure/Infra.Hosts/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/MigrationBackup/13c6add7/ConsoleUi/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/MigrationBackup/1abf21ee/Infrastructure/AppBootEx/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/MigrationBackup/6a755282/Modules/Quotations/Quotations.Services/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/MigrationBackup/99eadac7/Modules/Sales/Sales.Services/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/MigrationBackup/9d36020b/Modules/Portfolio/Portfolio.Services/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/MigrationBackup/ab5e6800/Infrastructure/Proxies/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/Portfolio/Portofolio.Services/PortfolioModule.cs: -------------------------------------------------------------------------------- 1 | using Contracts.Infrastructure; 2 | using iQuarc.AppBoot; 3 | 4 | namespace Portfolio.Services 5 | { 6 | [Service(nameof(PortfolioModule), typeof(IModule))] 7 | class PortfolioModule : IModule 8 | { 9 | private readonly IModulesHostContainer container; 10 | 11 | public PortfolioModule(IModulesHostContainer container) 12 | { 13 | this.container = container; 14 | } 15 | 16 | public void Initialize() 17 | { 18 | container.RegisterModule("Portfolio Module"); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/Portfolio/Portofolio.Services/PortfolioService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Contracts.Portfolio.Services; 5 | using Contracts.Quotations.Services; 6 | using iQuarc.AppBoot; 7 | 8 | namespace Portfolio.Services 9 | { 10 | [Service(typeof(IPortfolioService))] 11 | public class PortfolioService : IPortfolioService 12 | { 13 | private readonly IQuotationService quotationService; 14 | 15 | public PortfolioService(IQuotationService quotationService) 16 | { 17 | this.quotationService = quotationService; 18 | } 19 | 20 | public decimal GetPortfolioValue() 21 | { 22 | var securities = GetCurrentUserSecurities().ToArray(); 23 | DateTime to = DateTime.UtcNow; 24 | DateTime from = to.AddHours(-1); 25 | 26 | var quotes = quotationService.GetQuotations(securities, from, to); 27 | return quotes.Sum(q => q.BidPrice); 28 | } 29 | 30 | private IEnumerable GetCurrentUserSecurities() 31 | { 32 | return new[] {"AAPL.B.NASDAQ", "MSFT.B.NASDAQ"}; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/Quotation/Quotation.Services/QuotationService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Contracts; 7 | 8 | namespace Quotation.Services 9 | { 10 | public class QuotationService : IQuotationService 11 | { 12 | public IObservable GetQuotations(string exchange, string instrument) 13 | { 14 | throw new NotImplementedException(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/Quotations/Quotation.Services/QuotationsModule.cs: -------------------------------------------------------------------------------- 1 | using Contracts.Infrastructure; 2 | using iQuarc.AppBoot; 3 | 4 | namespace Quotations.Services 5 | { 6 | [Service(nameof(QuotationsModule), typeof(IModule))] 7 | class QuotationsModule : IModule 8 | { 9 | private readonly IModulesHostContainer container; 10 | 11 | public QuotationsModule(IModulesHostContainer container) 12 | { 13 | this.container = container; 14 | } 15 | 16 | public void Initialize() 17 | { 18 | container.RegisterModule("Quotations Module"); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/Sales/Sales.Services/IRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Sales.Services 5 | { 6 | interface IRepository 7 | { 8 | void Save(T entity); 9 | void SaveAll(IEnumerable entities); 10 | IQueryable GetEntities(); 11 | } 12 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/Sales/Sales.Services/SalesModule.cs: -------------------------------------------------------------------------------- 1 | using Contracts.Infrastructure; 2 | using iQuarc.AppBoot; 3 | 4 | namespace Sales.Services 5 | { 6 | [Service(nameof(SalesModule), typeof(IModule))] 7 | class SalesModule : IModule 8 | { 9 | private readonly IModulesHostContainer container; 10 | 11 | public SalesModule(IModulesHostContainer container) 12 | { 13 | this.container = container; 14 | } 15 | 16 | public void Initialize() 17 | { 18 | container.RegisterModule("Sales Module"); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/_Contracts/Infrastructure/IModulesHostContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Contracts.Infrastructure 9 | { 10 | public interface IModulesHostContainer 11 | { 12 | void RegisterModule(string moduleName); 13 | IEnumerable GetModules(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/_Contracts/Portfolio.Services/IPortfolioService.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts.Portfolio.Services 2 | { 3 | public interface IPortfolioService 4 | { 5 | decimal GetPortfolioValue(); 6 | } 7 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/_Contracts/Quotations.Services/IQuotationService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Contracts.Quotations.Services 4 | { 5 | public interface IQuotationService 6 | { 7 | Quotation[] GetQuotations(string exchange, string instrument, DateTime from, DateTime to); 8 | Quotation[] GetQuotations(string securityCode, DateTime from, DateTime to); 9 | Quotation[] GetQuotations(string[] securities, DateTime from, DateTime to); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/_Contracts/Quotations.Services/Quotation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Contracts.Quotations.Services 4 | { 5 | public class Quotation 6 | { 7 | public DateTime Timestamp { get; set; } 8 | public decimal BidPrice { get; set; } 9 | public decimal AskPrice { get; set; } 10 | public string SecurityCode { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/_Contracts/Sales.Services/IOrdersService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Contracts.Sales.Services 8 | { 9 | public interface IOrdersService 10 | { 11 | void PlaceSellLimitOrder(string securityCode, decimal sellingPrice, DateTime validUntil); 12 | void PlaceBuyLimitOrder(string securityCode, decimal buyingPrice, DateTime validUntil); 13 | LimitOrder[] GetLimitOrders(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /InterProcessCommunication/TradingApp/Modules/_Contracts/Sales.Services/LimitOrder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Contracts.Sales.Services 4 | { 5 | public class LimitOrder 6 | { 7 | public string SecurityCode { get; set; } 8 | public DateTime PlacedAt { get; set; } 9 | public OrderType Type { get; set; } 10 | public decimal Price { get; set; } 11 | 12 | public DateTime ValidUntil { get; set; } 13 | } 14 | 15 | public enum OrderType 16 | { 17 | Sell, 18 | Buy 19 | } 20 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 iQuarc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson5/Class2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LessonsSamples.Lesson5 8 | { 9 | class MyClass2 10 | { 11 | public void Boo() 12 | { 13 | var f = new Class2(); 14 | 15 | D d = new D(); 16 | f.Foo(d); 17 | } 18 | } 19 | 20 | class D : B 21 | { 22 | } 23 | 24 | class Class2 25 | { 26 | 27 | 28 | public void Foo(B b) 29 | { 30 | if (b is D) 31 | { 32 | // fix special case when b is D 33 | } 34 | } 35 | 36 | 37 | } 38 | 39 | class B 40 | { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson5/Modem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson5 4 | { 5 | public class Modem 6 | { 7 | public void Dial(string pno) 8 | { 9 | } 10 | 11 | public void Hangup() 12 | { 13 | } 14 | 15 | public void Send(char c) 16 | { 17 | } 18 | 19 | public char Recv() 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson5/Shapes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson5 4 | { 5 | class Square : Shape 6 | { 7 | public void Draw() 8 | { 9 | throw new NotImplementedException(); 10 | } 11 | } 12 | 13 | class Circle : Shape 14 | { 15 | public void Draw() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | } 20 | 21 | public interface Shape 22 | { 23 | void Draw(); 24 | } 25 | 26 | public class MyClass 27 | { 28 | public void DrawAllShapes(Shape[] shapes) 29 | 30 | { 31 | int i; 32 | for (i = 0; i < shapes.Length; i++) 33 | { 34 | shapes[i].Draw(); 35 | } 36 | } 37 | 38 | private void DrawCircle(Circle circle) 39 | { 40 | } 41 | 42 | private void DrawSquare(Square square) 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerConstructorSelection/App.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LessonsSamples.Lesson6.CoreContainerLifetime; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace LessonsSamples.Lesson6.CoreContainerConstructorSelection 6 | { 7 | public class App 8 | { 9 | private readonly IRootService rootService; 10 | 11 | public App(IRootService rootService) 12 | { 13 | this.rootService = rootService; 14 | } 15 | 16 | public void Hello() 17 | { 18 | foreach (var hello in rootService.GetHellos()) 19 | { 20 | Console.WriteLine(hello); 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerConstructorSelection/IRootService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using LessonsSamples.Lesson6.CoreContainerLifetime; 4 | 5 | namespace LessonsSamples.Lesson6.CoreContainerConstructorSelection 6 | { 7 | public interface IRootService 8 | { 9 | IEnumerable GetHellos(); 10 | } 11 | 12 | public class RootService : IRootService 13 | { 14 | public IService1 Service1 { get; } 15 | public IService2 Service2 { get; } 16 | 17 | public RootService(IService1 service1) 18 | { 19 | Service1 = service1; 20 | } 21 | 22 | public RootService(IService2 service2) 23 | { 24 | Service2 = service2; 25 | } 26 | 27 | public RootService(IService1 service1, IService2 service2) 28 | { 29 | Service1 = service1; 30 | Service2 = service2; 31 | } 32 | 33 | public IEnumerable GetHellos() 34 | { 35 | yield return $"Service1: {Service1?.Hello()}"; 36 | yield return $"Service2: {Service2?.Hello()}"; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerConstructorSelection/IService1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson6.CoreContainerConstructorSelection 4 | { 5 | public interface IService1 6 | { 7 | string Hello(); 8 | } 9 | 10 | class Service1 : IService1 11 | { 12 | public string Hello() => $"Hello from {GetType().Name}"; 13 | } 14 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerConstructorSelection/IService2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson6.CoreContainerConstructorSelection 4 | { 5 | public interface IService2 6 | { 7 | string Hello(); 8 | } 9 | 10 | class Service2 : IService2 11 | { 12 | public string Hello() => $"Hello from {GetType().Name}"; 13 | } 14 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerConstructorSelection/NetCoreConstructorSelectionDemo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace LessonsSamples.Lesson6.CoreContainerConstructorSelection 5 | { 6 | public static class NetCoreConstructorSelectionDemo 7 | { 8 | public static void MainFunc() 9 | { 10 | var services = new ServiceCollection(); 11 | ConfigureServices(services); 12 | ServiceProvider serviceProvider = services.BuildServiceProvider(); 13 | 14 | var app = serviceProvider.GetService(); 15 | app.Hello(); 16 | } 17 | 18 | private static void ConfigureServices(ServiceCollection services) 19 | { 20 | services.AddTransient(); 21 | services.AddTransient(); 22 | services.AddTransient(); 23 | 24 | services.AddTransient(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerLifetime/App.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace LessonsSamples.Lesson6.CoreContainerLifetime 5 | { 6 | public class App 7 | { 8 | private readonly IServiceProvider appServices; 9 | 10 | public App(IServiceProvider appServices) 11 | { 12 | this.appServices = appServices; 13 | } 14 | 15 | public void NewRequest() 16 | { 17 | using (var scope = appServices.CreateScope()) 18 | { 19 | IServiceProvider requestServices = scope.ServiceProvider; 20 | 21 | var controller = requestServices.GetService(); 22 | controller.ExecuteRequest(); 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerLifetime/IOperation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LessonsSamples.Lesson6.CoreContainerLifetime 8 | { 9 | public interface IOperation 10 | { 11 | Guid OperationId { get; } 12 | } 13 | 14 | public interface IOperationTransient : IOperation 15 | { 16 | } 17 | 18 | public interface IOperationScoped : IOperation 19 | { 20 | } 21 | 22 | public interface IOperationSingleton : IOperation 23 | { 24 | } 25 | 26 | public interface IOperationSingletonInstance : IOperation 27 | { 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerLifetime/MyController.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6.CoreContainerLifetime 2 | { 3 | public class MyController 4 | { 5 | private readonly IService service1; 6 | private readonly IService service2; 7 | 8 | public MyController(IService service1, IService service2) 9 | { 10 | this.service1 = service1; 11 | this.service2 = service2; 12 | } 13 | 14 | public void ExecuteRequest() 15 | { 16 | service1.ExecuteOperations("Service 1 operations"); 17 | service2.ExecuteOperations("Service 2 operations"); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/CoreContainerLifetime/Operation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson6.CoreContainerLifetime 4 | { 5 | public class Operation : IOperationTransient, 6 | IOperationScoped, 7 | IOperationSingleton, 8 | IOperationSingletonInstance 9 | { 10 | public Operation() : this(Guid.NewGuid()) 11 | { 12 | } 13 | 14 | public Operation(Guid id) 15 | { 16 | OperationId = id; 17 | } 18 | 19 | public Guid OperationId { get; private set; } 20 | } 21 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/AppConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using iQuarc.SystemEx; 3 | 4 | namespace LessonsSamples.Lesson6 5 | { 6 | class AppConsole : IConsole 7 | { 8 | public string AskInput(string message) 9 | { 10 | Console.WriteLine(); 11 | Console.WriteLine(message); 12 | 13 | return Console.ReadLine(); 14 | } 15 | 16 | public void WriteEntity(T salesOrderInfo) 17 | { 18 | Console.WriteLine(); 19 | Console.WriteLine($"--------------- {typeof(T).Name} ----------------"); 20 | var properties = ReflectionExtensions.GetEditableSimpleProperties(salesOrderInfo); 21 | foreach (var propertyInfo in properties) 22 | { 23 | Console.Write($"{propertyInfo.Name}: "); 24 | Console.WriteLine(propertyInfo.GetValue(salesOrderInfo)); 25 | } 26 | 27 | Console.WriteLine("-----------------------------------------------------"); 28 | } 29 | 30 | public void WriteLine(string line) 31 | { 32 | Console.WriteLine(line); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/IConsole.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6 2 | { 3 | internal interface IConsole 4 | { 5 | string AskInput(string message); 6 | void WriteEntity(T salesOrderInfo); 7 | void WriteLine(string line); 8 | } 9 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/IMovieConsoleCreator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson6 4 | { 5 | public interface IMovieConsoleCreator 6 | { 7 | void Open(); 8 | } 9 | 10 | class MovieConsoleCreator : IMovieConsoleCreator 11 | { 12 | private readonly ITextStorage storage; 13 | 14 | public MovieConsoleCreator(ITextStorage storage) 15 | { 16 | this.storage = storage; 17 | } 18 | 19 | public void Open() 20 | { 21 | Console.WriteLine("Insert One Movie on each line."); 22 | Console.WriteLine("Press ESC when you are done."); 23 | Console.WriteLine(); 24 | ConsoleKeyInfo c; 25 | do 26 | { 27 | c = Console.ReadKey(); 28 | 29 | if (char.IsLetterOrDigit(c.KeyChar)) 30 | storage.Write(new string(c.KeyChar, 1)); 31 | else if (c.Key == ConsoleKey.Enter) 32 | { 33 | Console.WriteLine(); 34 | storage.WriteLine(string.Empty); 35 | } 36 | 37 | } while (c.Key != ConsoleKey.Escape); 38 | 39 | Console.WriteLine(); 40 | Console.WriteLine("Thank you!. Your movies were created"); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/IMovieTranslator.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6 2 | { 3 | public interface IMovieTranslator 4 | { 5 | void TranslateTitles(); 6 | } 7 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/ITextStorage.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6 2 | { 3 | interface ITextStorage 4 | { 5 | void Write(string text); 6 | void WriteLine(string line); 7 | string ReadAll(); 8 | string ReadLine(int lineNumber); 9 | 10 | void Clear(); 11 | } 12 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/MovieTranslator.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6 2 | { 3 | class MovieTranslator : IMovieTranslator 4 | { 5 | private readonly ITextStorage storage; 6 | 7 | public MovieTranslator(ITextStorage storage) 8 | { 9 | this.storage = storage; 10 | } 11 | 12 | public void TranslateTitles() 13 | { 14 | string text = storage.ReadAll(); 15 | 16 | string transformed = text.ToUpperInvariant(); // being a demo translation = make all uppercase 17 | 18 | storage.Clear(); 19 | storage.Write(transformed); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/NetCoreContainerDemo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace LessonsSamples.Lesson6 4 | { 5 | public static class NetCoreContainerDemo 6 | { 7 | public static void MainFunc() 8 | { 9 | var services = new ServiceCollection(); 10 | ConfigureServices(services); 11 | ServiceProvider serviceProvider = services.BuildServiceProvider(); 12 | 13 | var app = serviceProvider.GetService(); 14 | app.Run(); 15 | } 16 | 17 | private static void ConfigureServices(ServiceCollection services) 18 | { 19 | services 20 | .AddTransient() 21 | .AddTransient() 22 | .AddScoped() 23 | 24 | // Demo the difference between Scoped and Transient. This being the root container, Scoped will be promoted to Singleton 25 | .AddTransient() 26 | ; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI-Demo/UnityDemo.cs: -------------------------------------------------------------------------------- 1 | using Unity; 2 | using Unity.Lifetime; 3 | 4 | namespace LessonsSamples.Lesson6 5 | { 6 | static class UnityDemo 7 | { 8 | public static void MainFunc() 9 | { 10 | UnityContainer container = new UnityContainer(); 11 | 12 | container.RegisterType(); 13 | container.RegisterType(); 14 | 15 | // Demo the difference between PerResolveLifetimeManager and TransientLifetimeManager 16 | container.RegisterType(new PerResolveLifetimeManager()); 17 | 18 | 19 | var app = container.Resolve(); 20 | app.Run(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI_AndDisposable/Model.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace LessonsSamples.Lesson6.DI_AndDisposable 5 | { 6 | internal class Order 7 | { 8 | public int Id { get; set; } 9 | public int Year { get; set; } 10 | public ICollection OrderLines { get; set; } 11 | public string Header { get; set; } 12 | public Status Status { get; set; } 13 | } 14 | 15 | internal class OrderLine 16 | { 17 | public decimal Ammount { get; set; } 18 | public Status Status { get; set; } 19 | public int OrderId { get; set; } 20 | } 21 | 22 | internal enum Status 23 | { 24 | PreCalculated, 25 | Reviewed 26 | } 27 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/DI_AndDisposable/RepositoryFactory.cs: -------------------------------------------------------------------------------- 1 | using CommonServiceLocator; 2 | 3 | namespace LessonsSamples.Lesson6.DI_AndDisposable 4 | { 5 | interface IRepositoryFactory 6 | { 7 | IRepository CreateRepository(); 8 | IUnitOfWork CreateUnitOfWork(); 9 | } 10 | 11 | class RepositoryFactory : IRepositoryFactory 12 | { 13 | public IRepository CreateRepository() 14 | { 15 | return ServiceLocator.Current.GetInstance(); 16 | } 17 | 18 | public IUnitOfWork CreateUnitOfWork() 19 | { 20 | return ServiceLocator.Current.GetInstance(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/Expenses/1.ExpenseData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson6.Expenses 4 | { 5 | public class ExpenseData 6 | { 7 | public DateTime Date { get; set; } 8 | public string Description { get; set; } 9 | public decimal Amount { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/Expenses/1.IExpensesService.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6.Expenses 2 | { 3 | interface IExpensesService 4 | { 5 | void Process(ExpenseData expense); 6 | void Approve(ExpenseData expense); 7 | } 8 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/IMovieProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LessonsSamples.Lesson6 4 | { 5 | interface IMovieProvider 6 | { 7 | IEnumerable GetAll(); 8 | } 9 | 10 | class EmptyFilter : ICountryFilter 11 | { 12 | } 13 | 14 | interface ICountryFilter 15 | { 16 | } 17 | 18 | interface ITitleMatcher 19 | { 20 | } 21 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/Logger/LogEntry.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6.Logger 2 | { 3 | public class LogEntry 4 | { 5 | public string Headline { get; private set; } 6 | public string Message { get; private set; } 7 | public Severity Error { get; private set; } 8 | 9 | public LogEntry(string headline, string message, Severity error) 10 | { 11 | Headline = headline; 12 | Message = message; 13 | Error = error; 14 | } 15 | } 16 | 17 | public enum Severity 18 | { 19 | Error, 20 | Warning, 21 | Info, 22 | Trace, 23 | Debug 24 | } 25 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/Movie.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6 2 | { 3 | public class Movie 4 | { 5 | public string Title { get; set; } 6 | public int Rating { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/MovieLister_SL.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CommonServiceLocator; 4 | 5 | namespace LessonsSamples.Lesson6.SL 6 | { 7 | class MovieLister 8 | { 9 | private readonly IServiceLocator serviceLocator; 10 | 11 | public MovieLister() 12 | { 13 | serviceLocator = ServiceLocator.Current; 14 | } 15 | 16 | public MovieLister(IServiceLocator serviceLocator) 17 | { 18 | this.serviceLocator = serviceLocator; 19 | } 20 | 21 | public Movie[] GetMoviesDirectedBy(string director) 22 | { 23 | IMovieProvider movieProvider = serviceLocator.GetInstance(); 24 | 25 | IEnumerable allMovies = movieProvider.GetAll(); 26 | List resultList = new List(); 27 | foreach (var movie in allMovies) 28 | { 29 | if (IsDirectedBy(movie, director)) 30 | resultList.Add(movie); 31 | } 32 | 33 | return resultList.ToArray(); 34 | } 35 | 36 | private bool IsDirectedBy(Movie movie, string director) 37 | { 38 | throw new NotImplementedException(); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/ServiceLocatorTestability/INumberGeneratorService.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson6.ServiceLocatorTestability 2 | { 3 | public interface INumberGeneratorService 4 | { 5 | int GenerateNumber(); 6 | } 7 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/ServiceLocatorTestability/ServiceLocatorDoubleStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CommonServiceLocator; 3 | 4 | namespace LessonsSamples.Lesson6.ServiceLocatorTestability 5 | { 6 | public static class ServiceLocatorDoubleStorage 7 | { 8 | [ThreadStatic] 9 | private static IServiceLocator current; 10 | 11 | public static IServiceLocator Current 12 | { 13 | get { return current; } 14 | } 15 | 16 | public static void SetInstance(IServiceLocator sl) 17 | { 18 | current = sl; 19 | } 20 | 21 | public static void Cleanup() 22 | { 23 | SetInstance(null); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson6/ServiceLocatorTestability/UnderTest.cs: -------------------------------------------------------------------------------- 1 | using CommonServiceLocator; 2 | 3 | namespace LessonsSamples.Lesson6.ServiceLocatorTestability 4 | { 5 | public class UnderTest 6 | { 7 | public bool IsOdd() 8 | { 9 | var service = ServiceLocator.Current.GetInstance(); 10 | int number = service.GenerateNumber(); 11 | return number%2 == 1; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClassLibrary1.Lesson7 4 | { 5 | public class PerDiemMealExpenses : MealExpenses 6 | { 7 | public int GetTotal() 8 | { 9 | // return the per diem default 10 | throw new NotImplementedException(); 11 | } 12 | } 13 | 14 | class MealExpensesNotFound : Exception 15 | { 16 | } 17 | 18 | public class MealExpenses 19 | { 20 | public int GetTotal() 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | } 25 | 26 | public class DeviceShutdownException : Exception 27 | { 28 | } 29 | 30 | public static class Logger 31 | { 32 | public static void Log(string p0) 33 | { 34 | throw new NotImplementedException(); 35 | } 36 | 37 | public static void Log(DeviceShutdownException p0) 38 | { 39 | throw new NotImplementedException(); 40 | } 41 | } 42 | 43 | class Record 44 | { 45 | public int GetStatus() 46 | { 47 | throw new NotImplementedException(); 48 | } 49 | } 50 | 51 | public class DeviceHandle 52 | { 53 | public static DeviceHandle INVALID; 54 | } 55 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/10_PageXmlExportClient.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LessonsSamples.Lesson7.CohesionCoupling 4 | { 5 | class PageXmlExportClient 6 | { 7 | public void Func(IEnumerable customers) 8 | { 9 | var exporter = new PageXmlExport(); 10 | 11 | foreach (var customer in customers) 12 | { 13 | exporter.ExportCustomerPage("{0}_{1}_{2}", true, customer, 10, true); 14 | } 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/12_PageXmlExportClientcs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using CommonServiceLocator; 3 | 4 | namespace LessonsSamples.Lesson7.CohesionCoupling 5 | { 6 | class PageXmlExportClient_2 7 | { 8 | public void ExportDataForCustomers(IEnumerable customers) 9 | { 10 | ICrmService crmService = ServiceLocator.Current.GetInstance(); 11 | ILocationService locationService = ServiceLocator.Current.GetInstance(); 12 | var exporter = new PageXmlExport_2("{0}_{1}_{2}", true, 10, true, crmService, locationService); 13 | 14 | foreach (var customer in customers) 15 | { 16 | PageData userInput = GetUserInput(customer); 17 | exporter.ExportCustomerPageWithExternalData(customer, userInput); 18 | } 19 | } 20 | 21 | private PageData GetUserInput(string customer) 22 | { 23 | // TODO: take this data from a view model 24 | return new PageData(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/13_PageXmlExportClient.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using CommonServiceLocator; 3 | 4 | namespace LessonsSamples.Lesson7.CohesionCoupling 5 | { 6 | class PageXmlExportClient_3 7 | { 8 | public void ExportDataForCustomers(IEnumerable customers) 9 | { 10 | ICrmService crmService = ServiceLocator.Current.GetInstance(); 11 | ILocationService locationService = ServiceLocator.Current.GetInstance(); 12 | IPageFileWriter pageWriter = ServiceLocator.Current.GetInstance(); 13 | 14 | var exporter = new PageXmlExport_3(pageWriter, 10, true, crmService, locationService); 15 | 16 | foreach (var customer in customers) 17 | { 18 | PageData userInput = GetUserInput(customer); 19 | exporter.ExportCustomerPageWithExternalData(customer, userInput); 20 | } 21 | } 22 | 23 | private PageData GetUserInput(string customer) 24 | { 25 | // TODO: take this data from a view model 26 | return new PageData(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/ICrmService.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson7.CohesionCoupling 2 | { 3 | public interface ICrmService 4 | { 5 | CustomerInfo GetCustomerInfo(string customerName); 6 | } 7 | 8 | public class CustomerInfo 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/IExportDataProvider_4.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson7.CohesionCoupling 2 | { 3 | public interface IExportDataProvider_4 4 | { 5 | CustomerInfo GetCustomerInfo(string name); 6 | Coordinates GetCoordinates(string city, string street, string number); 7 | } 8 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/ILocationService.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson7.CohesionCoupling 2 | { 3 | public interface ILocationService 4 | { 5 | Coordinates GetCoordinates(string city, string street, string number); 6 | } 7 | 8 | public class Coordinates 9 | { 10 | public double Latitude { get; set; } 11 | public double Longitude { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/IPageFileWriter.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson7.CohesionCoupling 2 | { 3 | public interface IPageFileWriter 4 | { 5 | bool WriteFile(PageXml page, string fileType); // fileType=="CustomerPage" 6 | } 7 | 8 | public static class PageFileWriterExtensions 9 | { 10 | public static bool WriteFile(this IPageFileWriter writer, PageXml page) 11 | { 12 | return writer.WriteFile(page, string.Empty); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/IRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace LessonsSamples.Lesson7.CohesionCoupling 5 | { 6 | public interface IRepository 7 | { 8 | IQueryable GetEntities() where TDbEntity : class; 9 | IUnitOfWork CreateUnitOfWork(); 10 | } 11 | 12 | public interface IUnitOfWork : IRepository, IDisposable 13 | { 14 | void SaveChanges(); 15 | 16 | void Add(T entity) where T : class; 17 | 18 | void Delete(T entity) where T : class; 19 | } 20 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/PageData.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson7.CohesionCoupling 2 | { 3 | public class PageData 4 | { 5 | public CustomerData CustomerData { get; set; } 6 | } 7 | 8 | public class CustomerData 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/PageXml.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LessonsSamples.Lesson7.CohesionCoupling 4 | { 5 | public class PageXml 6 | { 7 | public CustomerXml Customer { get; set; } 8 | 9 | //.... other properties that describe the XML format of a page w/ customer data 10 | } 11 | 12 | public class CustomerXml 13 | { 14 | public string Name { get; set; } 15 | public List Addresses { get; set; } 16 | 17 | //.... other properties that describe the XML format of a customer 18 | } 19 | 20 | public class AddressXml 21 | { 22 | public string Street { get; set; } 23 | public string City { get; set; } 24 | public string Number { get; set; } 25 | public string Coordinates { get; set; } 26 | } 27 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/ErrorHandling/CodeSnippet.cs: -------------------------------------------------------------------------------- 1 | using ClassLibrary1.Lesson7; 2 | 3 | namespace LessonsSamples.Lesson7.ErrorHandling 4 | { 5 | class CodeSnippet 6 | { 7 | private ExpensesReport expenseReport; 8 | 9 | private int Ex(Employee employee) 10 | { 11 | int m_total = 0; 12 | try 13 | { 14 | MealExpenses expenses = expenseReport.GetMeals(employee); 15 | m_total += expenses.GetTotal(); 16 | } 17 | catch (MealExpensesNotFound e) 18 | { 19 | m_total += GetMealPerDiem(); 20 | } 21 | 22 | return m_total; 23 | } 24 | 25 | private int GetMealPerDiem() 26 | { 27 | throw new System.NotImplementedException(); 28 | } 29 | } 30 | 31 | class Employee 32 | { 33 | } 34 | 35 | class ExpensesReport 36 | { 37 | public MealExpenses GetMeals(object employee) 38 | { 39 | throw new System.NotImplementedException(); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/GoodClasses/Geometry/CircleGeometry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LessonsSamples.Lesson7.GoodClasses.Procedural; 3 | 4 | namespace LessonsSamples.Lesson7.GoodClasses.Geometry 5 | { 6 | class SquareGeometry : GeometryCalculator 7 | { 8 | public override double GetArea(Square s) 9 | { 10 | return s.Side * s.Side; 11 | } 12 | } 13 | 14 | class RectangleGeometry : GeometryCalculator 15 | { 16 | public override double GetArea(Rectangle r) 17 | { 18 | return r.Height*r.Width; 19 | } 20 | } 21 | 22 | class CircleGeometry : GeometryCalculator 23 | { 24 | public override double GetArea(Circle c) 25 | { 26 | return Math.PI * c.Radius * c.Radius; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/GoodClasses/Geometry/GeometryCalculatorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using LessonsSamples.Lesson7.GoodClasses.Procedural; 4 | 5 | namespace LessonsSamples.Lesson7.GoodClasses.Geometry 6 | { 7 | internal interface IGeometryCalculatorFactory 8 | { 9 | IGeometryCalculator GetCalculator(Type shape); 10 | } 11 | 12 | class GeometryCalculatorFactory : IGeometryCalculatorFactory 13 | { 14 | private readonly Dictionary> constructors = new Dictionary> 15 | { 16 | {typeof (Square), () => new SquareGeometry()}, 17 | {typeof (Rectangle), () => new RectangleGeometry()}, 18 | {typeof (Circle), () => new CircleGeometry()}, 19 | }; 20 | 21 | public IGeometryCalculator GetCalculator(Type shape) 22 | { 23 | var constructor = constructors[shape]; 24 | return constructor(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/GoodClasses/Geometry/IGeometryCalculator.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace LessonsSamples.Lesson7.GoodClasses.Geometry 3 | { 4 | class Geometry : IGeometryCalculator 5 | { 6 | private readonly IGeometryCalculatorFactory factory = new GeometryCalculatorFactory(); 7 | 8 | public double GetArea(object shape) 9 | { 10 | IGeometryCalculator calculator = factory.GetCalculator(shape.GetType()); 11 | return calculator.GetArea(shape); 12 | } 13 | 14 | 15 | } 16 | 17 | interface IGeometryCalculator 18 | { 19 | double GetArea(object shape); 20 | } 21 | 22 | interface IGeometryCalculator : IGeometryCalculator 23 | { 24 | double GetArea(T shape); 25 | } 26 | 27 | abstract class GeometryCalculator : IGeometryCalculator 28 | { 29 | public abstract double GetArea(T shape); 30 | 31 | public double GetArea(object shape) 32 | { 33 | return GetArea((T) shape); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/GoodClasses/Geometry/PolymorphicShapes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ClassLibrary1; 3 | 4 | namespace LessonsSamples.Lesson7.GoodClasses.Polimorphic 5 | { 6 | interface IShape 7 | { 8 | double GetArea(); 9 | } 10 | 11 | class Square : IShape 12 | { 13 | private Point topLeft; 14 | private double side; 15 | 16 | public double GetArea() 17 | { 18 | return side * side; 19 | } 20 | } 21 | 22 | class Rectangle : IShape 23 | { 24 | private Point topLeft; 25 | private double height; 26 | private double width; 27 | 28 | public double GetArea() 29 | { 30 | return height*width; 31 | } 32 | } 33 | 34 | class Circle : IShape 35 | { 36 | private Point center; 37 | private double radius; 38 | 39 | public double GetArea() 40 | { 41 | return Math.PI*radius*radius; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/GoodClasses/Geometry/ProceduralShapes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ClassLibrary1; 3 | 4 | namespace LessonsSamples.Lesson7.GoodClasses.Procedural 5 | { 6 | class Square 7 | { 8 | public Point TopLeft; 9 | public double Side; 10 | } 11 | 12 | class Rectangle 13 | { 14 | public Point TopLeft; 15 | public double Height; 16 | public double Width; 17 | } 18 | 19 | class Circle 20 | { 21 | public Point Center; 22 | public double Radius; 23 | } 24 | 25 | class Geometry 26 | { 27 | public double GetArea(object shape) 28 | { 29 | if (shape is Square) 30 | { 31 | Square s = (Square) shape; 32 | return s.Side*s.Side; 33 | } 34 | else if (shape is Rectangle) 35 | { 36 | Rectangle r = (Rectangle) shape; 37 | return r.Height*r.Width; 38 | } 39 | else if (shape is Circle) 40 | { 41 | Circle c = (Circle) shape; 42 | return Math.PI*c.Radius*c.Radius; 43 | } 44 | else 45 | throw new NotSupportedException(); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/InheritanceComposition/AccountClientCode.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson7.InheritanceComposition 2 | { 3 | static class AccountClientCode 4 | { 5 | public static decimal CalculateTotalInterestValue(Account[] accounts) 6 | { 7 | decimal amount = 0; 8 | for (int i = 0; i < accounts.Length; i++) 9 | { 10 | decimal interest = accounts[i].MonthlyInterest(); 11 | 12 | if (accounts[i] is AutoLoanAccount) 13 | interest = -1*interest; 14 | 15 | amount += interest; 16 | } 17 | 18 | return amount; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/InheritanceComposition/ILogMessageParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson7.InheritanceComposition 4 | { 5 | internal interface ILogMessageParser 6 | { 7 | string GetVersion(string logMessage, int messageIndex); 8 | DateTime GetTime(string logMessage, int messageIndex); 9 | int GetSeverity(string logMessage, int messageIndex); 10 | string GetDescription(string logMessage, int messageIndex); 11 | } 12 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/InheritanceComposition/LogEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LessonsSamples.Lesson7.InheritanceComposition 4 | { 5 | class LogEntry 6 | { 7 | public DateTime Time { get; set; } 8 | public int Severity { get; set; } 9 | public string Version { get; set; } 10 | public string Description { get; set; } 11 | public string Body { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/InheritanceComposition/LogSource.cd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | AwAAAACAAIAAAAAAYAAAAAAAAAAAAAAAAAAACAAAAAA= 7 | Lesson7\InheritanceComposition\LogSource.cs 8 | 9 | 10 | 11 | 12 | 13 | AQAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAA= 14 | Lesson7\InheritanceComposition\LogSource.cs 15 | 16 | 17 | 18 | 19 | 20 | AQAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAA= 21 | Lesson7\InheritanceComposition\LogSource.cs 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson7/InheritanceComposition/Month.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson7.InheritanceComposition 2 | { 3 | public struct Month 4 | { 5 | public int Year; 6 | public int MonthOfYear; 7 | } 8 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/AuditLog/EntityInterceptor.cs: -------------------------------------------------------------------------------- 1 | using iQuarc.DataAccess; 2 | 3 | namespace LessonsSamples.Lesson8.AuditLog 4 | { 5 | public abstract class EntityInterceptor : IEntityInterceptor where T : class 6 | { 7 | public virtual void OnLoad(IEntityEntry entry, IRepository repository) 8 | { 9 | } 10 | 11 | public virtual void OnSave(IEntityEntry entry, IUnitOfWork unitOfWork) 12 | { 13 | } 14 | 15 | public virtual void OnDelete(IEntityEntry entry, IUnitOfWork unitOfWork) 16 | { 17 | } 18 | 19 | public void OnLoad(IEntityEntry entry, IRepository repository) 20 | { 21 | OnLoad(entry.Convert(), repository); 22 | } 23 | 24 | public void OnDelete(IEntityEntry entry, IUnitOfWork unitOfWork) 25 | { 26 | OnDelete(entry.Convert(), unitOfWork); 27 | } 28 | 29 | public void OnSave(IEntityEntry entry, IUnitOfWork unitOfWork) 30 | { 31 | OnSave(entry.Convert(), unitOfWork); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/AuditLog/IAuditLog.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson8.AuditLog 2 | { 3 | internal interface IAuditLog 4 | { 5 | void Write(AuditType read, string empty, User user); 6 | } 7 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/RowLevelAuth/IRowAuthPoliciesContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace LessonsSamples.Lesson8.RowLevelAuth 5 | { 6 | interface IRowAuthPoliciesContainer 7 | { 8 | bool HasPolicy(); 9 | IRowAuthPolicy GetPolicy(); 10 | RowAuthPolicy Register(Expression> selector); 11 | } 12 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/Validation/AddressValidationRules.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson8.Validation 2 | { 3 | class AddressValidationRules : EntityValidationRulesRegistrator
4 | { 5 | protected override void RegisterTo(IValidationRulesSet
rulesSet) 6 | { 7 | rulesSet 8 | .Required(a => a.Street) 9 | 10 | .DefineNewState(a => a.CountryID == (int) Country.RO) 11 | .Required(a => a.Number, ValidationMessages.AddressNumber) 12 | .Required(a => a.PostCode) 13 | .RegularExpression(a => a.PostCode, postCodeRegex) 14 | 15 | .DefineNewState(a => a.CountryID != (int) Country.RO) 16 | .Required(a => a.City) 17 | ; 18 | } 19 | 20 | private string postCodeRegex; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/Validation/Country.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson8.Validation 2 | { 3 | enum Country 4 | { 5 | RO 6 | } 7 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/Validation/EntityValidationRulesRegistrator.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson8.Validation 2 | { 3 | class EntityValidationRulesRegistrator 4 | { 5 | protected virtual void RegisterTo(IValidationRulesSet rulesSet) 6 | { 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/Validation/IValidationRulesSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace LessonsSamples.Lesson8.Validation 5 | { 6 | interface IValidationRulesSet 7 | { 8 | IValidationRulesSet Required(Expression> property); 9 | IValidationRulesSet Required(Expression> property, string messageKey); 10 | 11 | IValidationRulesSet DefineNewState(Func state); 12 | IValidationRulesSet RegularExpression(Expression> property, string postCodeRegex); 13 | } 14 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Lesson8/Validation/ValidationMessages.cs: -------------------------------------------------------------------------------- 1 | namespace LessonsSamples.Lesson8.Validation 2 | { 3 | internal class ValidationMessages 4 | { 5 | public static string AddressNumber; 6 | } 7 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Point.cs: -------------------------------------------------------------------------------- 1 | namespace ClassLibrary1 2 | { 3 | public class Point 4 | { 5 | public double X { get; set; } 6 | public double Y { get; set; } 7 | } 8 | 9 | interface IPoint 10 | { 11 | double X { get; } 12 | double Y { get; } 13 | void SetCartesian(double x, double y); 14 | 15 | double R { get; } 16 | double Theta { get; } 17 | void SetPolar(double r, double theta); 18 | } 19 | } -------------------------------------------------------------------------------- /LessonsSamples/LessonsSamples/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using iQuarc.AppBoot; 7 | using LessonsSamples.Lesson6; 8 | using LessonsSamples.Lesson6.CoreContainerConstructorSelection; 9 | using LessonsSamples.Lesson6.CoreContainerLifetime; 10 | using LessonsSamples.Lesson6.ServiceLocatorTestability; 11 | 12 | namespace LessonsSamples 13 | { 14 | class Program 15 | { 16 | static void Main(string[] args) 17 | { 18 | //TestRunner.RunTests(); 19 | 20 | UnityDemo.MainFunc(); 21 | //NetCoreContainerDemo.MainFunc(); 22 | //NetCoreConstructorSelectionDemo.MainFunc(); 23 | 24 | 25 | //NetCoreLifetimeDemo.MainFunc(); 26 | 27 | Console.WriteLine(); 28 | Console.WriteLine("Demo ran. Press enter to close"); 29 | Console.ReadLine(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MultitenancySamples/SeparatedDbsConsoleDemo/SeparatedDbs.ConsoleDemo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MultitenancySamples/SeparatedDbsConsoleDemo/SeparatedDbs.ConsoleDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeparatedDbs.ConsoleDemo 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MultitenancySamples/SeparatedDbsConsoleDemo/SeparatedDbs.DataAccess/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /MultitenancySamples/SeparatedDbsConsoleDemo/SeparatedDbs.DataAccess/MultitenancyDbContextFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Claims; 2 | using iQuarc.DataAccess; 3 | 4 | namespace SeparatedDbs.DataAccess 5 | { 6 | public class MultitenancyDbContextFactory : IDbContextFactory 7 | { 8 | public IDbContextWrapper CreateContext() 9 | { 10 | string tenantKey = GetTenantKeyFromCurrentUser(); 11 | string connectionName = $"{tenantKey}_PhysioDb"; 12 | return new DbContextWrapper(new PhysioEntities(connectionName)); 13 | } 14 | 15 | private string GetTenantKeyFromCurrentUser() 16 | { 17 | const string tenantKeyClaim = "tenant_key"; 18 | Claim tenantClaim = ClaimsPrincipal.Current.FindFirst(tenantKeyClaim); 19 | return tenantClaim.Value; 20 | } 21 | } 22 | 23 | //TODO: generate this w/ EF 24 | } 25 | -------------------------------------------------------------------------------- /MultitenancySamples/SeparatedDbsConsoleDemo/SeparatedDbs.DataAccess/PhysioEntities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Entity; 3 | 4 | namespace SeparatedDbs.DataAccess 5 | { 6 | public class PhysioEntities : DbContext 7 | { 8 | public PhysioEntities(string connectionName) 9 | { 10 | throw new NotImplementedException(); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /MultitenancySamples/SeparatedDbsConsoleDemo/SeparatedDbs.DataAccess/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.ConsoleDemo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/DbContextFactory.cs: -------------------------------------------------------------------------------- 1 | using iQuarc.DataAccess; 2 | 3 | namespace SharedDb.DataAccess 4 | { 5 | class DbContextFactory : DbContextFactory 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/EmptyInterceptorsResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using iQuarc.DataAccess; 5 | 6 | namespace SharedDb.DataAccess 7 | { 8 | public class EmptyInterceptorsResolver : IInterceptorsResolver 9 | { 10 | public IEnumerable GetGlobalInterceptors() 11 | { 12 | return Enumerable.Empty(); 13 | } 14 | 15 | public IEnumerable GetEntityInterceptors(Type entityType) 16 | { 17 | return Enumerable.Empty(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/ITenantEntity.cs: -------------------------------------------------------------------------------- 1 | namespace SharedDb.DataAccess 2 | { 3 | interface ITenantEntity 4 | { 5 | int TenantID { get; set; } 6 | } 7 | 8 | public partial class Patient 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/PatientHistory.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace SharedDb.DataAccess 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class PatientHistory 16 | { 17 | public int ID { get; set; } 18 | public int PatientFileID { get; set; } 19 | public int DiagnosticID { get; set; } 20 | public int TenantID { get; set; } 21 | public string EntryDescription { get; set; } 22 | public System.DateTime EntryDate { get; set; } 23 | 24 | public virtual Diagnostic Diagnostic { get; set; } 25 | public virtual PatientFile PatientFile { get; set; } 26 | public virtual Tenant Tenant { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/Physio.Designer.cs: -------------------------------------------------------------------------------- 1 | // T4 code generation is enabled for model 'C:\D\Projects\iQuarc\Code-Design-Training\MultitenancySamples\SharedDbConsoleDemo\SharedDb.DataAccess\Physio.edmx'. 2 | // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer 3 | // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model 4 | // is open in the designer. 5 | 6 | // If no context and entity classes have been generated, it may be because you created an empty model but 7 | // have not yet chosen which version of Entity Framework to use. To generate a context class and entity 8 | // classes for your model, open the model in the designer, right-click on the designer surface, and 9 | // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation 10 | // Item...'. -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/Physio.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/TenantEntities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharedDb.DataAccess 8 | { 9 | //TODO: modify the code generator to generate these entities to implement ITenantEntity 10 | public partial class Patient : ITenantEntity 11 | { 12 | } 13 | 14 | public partial class PatientFile : ITenantEntity 15 | { 16 | } 17 | 18 | public partial class PatientHistory : ITenantEntity 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.DataAccess/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.Database/dbo/Tables/Diagnostics.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Diagnostics] ( 2 | [ID] INT IDENTITY (1, 1) NOT NULL, 3 | [Name] NVARCHAR (500) NULL, 4 | [Description] NVARCHAR (500) NULL, 5 | [Simptoms] NVARCHAR (50) NULL, 6 | CONSTRAINT [PK_Diagnostics] PRIMARY KEY CLUSTERED ([ID] ASC) 7 | ); 8 | 9 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.Database/dbo/Tables/PatientFile.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[PatientFile] ( 2 | [ID] INT IDENTITY (1, 1) NOT NULL, 3 | [TenantID] INT NOT NULL, 4 | [PatientID] INT NOT NULL, 5 | [CreationDate] DATETIME2 (7) NOT NULL, 6 | CONSTRAINT [PK_PatientFile] PRIMARY KEY CLUSTERED ([ID] ASC), 7 | CONSTRAINT [FK_PatientFile_Patients] FOREIGN KEY ([PatientID]) REFERENCES [dbo].[Patients] ([ID]), 8 | CONSTRAINT [FK_PatientFile_Tenants] FOREIGN KEY ([TenantID]) REFERENCES [dbo].[Tenants] ([ID]) 9 | ); 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.Database/dbo/Tables/PatientHistory.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[PatientHistory] ( 2 | [ID] INT IDENTITY (1, 1) NOT NULL, 3 | [PatientFileID] INT NOT NULL, 4 | [DiagnosticID] INT NOT NULL, 5 | [TenantID] INT NOT NULL, 6 | [EntryDescription] NVARCHAR (500) NOT NULL, 7 | [EntryDate] DATETIME2 (7) NOT NULL, 8 | CONSTRAINT [PK_PatientHistory] PRIMARY KEY CLUSTERED ([ID] ASC), 9 | CONSTRAINT [FK_PatientHistory_Diagnostics] FOREIGN KEY ([DiagnosticID]) REFERENCES [dbo].[Diagnostics] ([ID]), 10 | CONSTRAINT [FK_PatientHistory_PatientFile] FOREIGN KEY ([PatientFileID]) REFERENCES [dbo].[PatientFile] ([ID]), 11 | CONSTRAINT [FK_PatientHistory_Tenants] FOREIGN KEY ([TenantID]) REFERENCES [dbo].[Tenants] ([ID]) 12 | ); 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.Database/dbo/Tables/Patients.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Patients] ( 2 | [ID] INT IDENTITY (1, 1) NOT NULL, 3 | [TenantID] INT NOT NULL, 4 | [Name] NVARCHAR (50) NOT NULL, 5 | [DateOfBirth] DATETIME2 (7) NOT NULL, 6 | CONSTRAINT [PK_Patients] PRIMARY KEY CLUSTERED ([ID] ASC), 7 | CONSTRAINT [FK_Patients_Tenants] FOREIGN KEY ([TenantID]) REFERENCES [dbo].[Tenants] ([ID]) 8 | ); 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /MultitenancySamples/SharedDbConsoleDemo/SharedDb.Database/dbo/Tables/Tenants.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Tenants] ( 2 | [ID] INT IDENTITY (1, 1) NOT NULL, 3 | [Name] NVARCHAR (50) NOT NULL, 4 | [Key] NVARCHAR (50) NOT NULL, 5 | CONSTRAINT [PK_Tenants] PRIMARY KEY CLUSTERED ([ID] ASC) 6 | ); 7 | 8 | 9 | GO 10 | CREATE UNIQUE NONCLUSTERED INDEX [UK_Tenants_Key] 11 | ON [dbo].[Tenants]([Key] ASC); 12 | 13 | --------------------------------------------------------------------------------