.NET Core console application;net core 87
.NET events;net events 204
[CheckAuthorization] aspect;CheckAuthorization 354
[CircuitBreaker] attribute;CircuitBreaker 349
[Transaction] attribute;Transaction 349
@model directive 57
abstract classes vs. interfaces 68–69
Abstract Factory pattern 7–7, 130–130, 191–193
abstract keyword 69
ActionDescriptor property 397, 431
Activator.CreateInstance 156, 157
Activator class 155
ActivatorUtilities class 485–486, 487, 489, 497
AddProductCommand property 223, 225
AddProduct method 223
AddScoped method 378, 472, 479
AddSingleton<T>() method 175
AddSingleton method 231, 378, 472, 479
AddTransient method 378, 472, 479, 482
AdjustInventory command 321, 323
AdjustInventoryService 323, 324, 335, 335, 401, 436, 475
AdjustInventoryViewModel 321
Administrator role 331
ADO.NET Data Services 46
AlertUser method 298
Ambient Context anti-pattern
accessing time through 146–148
ambiguity, removing
refactoring by 417–418, 455–455, 487–487
using ActivatorUtilities 485–486
using conditional registrations 453–454
AOP (Aspect-Oriented Programming) 31, 31, 302, 302
APIs (application programming interfaces), registering 409–412, 447–451, 480–483
App class 227
applications
ApplyDiscountFor method 104, 108
ASP.NET Core framework
IUserContext Adapter specific to 71–72
MVC applications, composing 228–234
using custom controller activators in 230–231
ASP.NET Core web application 87
Aspect-Oriented Programming
AspNetUserContextAdapter class 72, 72, 72, 72, 72, 158, 158, 159, 195, 197, 198, 204, 243, 243, 243, 260, 367, 370, 370, 371, 371, 375, 375
Assert.Equal method 24
Assert.Fail method 312
asynchronous application models 276–278
async keyword 233
AsyncScopedLifestyle 444
attribute parameter 111
auditing
implementing audit trail 203
implementing using Decorators 287–290
AuditingCommandServiceDecorator<TCommand> 329
AuditingUserRepositoryDecorator class 288, 288, 288, 289, 289, 290–290, 306, 307, 308, 327
authorization 334
Autofac.Core.KeyedService 424
Autofac container 380
Auto-Registration 361, 376, 379, 383, 474
AutoWireContainer 365, 367, 371
Auto-Wiring 363–364, 364, 371, 410, 413, 415, 417, 430, 453, 489
await keyword 233
AzureProductRepository class 132, 132
Azure Table data access layer 47
Azure Table Service 76
BCL (Base Class Library) 16, 26, 44, 65
BeginLifetimeScope method 407
BeginScope method 441
big object graphs 98
Binding markup extension 225
Bitmap 108
BuildServiceProvider 469
bus factor 386
caching 291
CalculateRoute 191
Captive Dependencies 110, 266–269, 446–446
Castle.DynamicProxy.IInterceptor interface 344
Castle.DynamicProxy.IInvocation 347
Chain of Responsibility pattern 287
CircuitBreakerAttribute 353
CircuitBreaker class 295
CircuitBreakerInterceptor
applying inside Composition Root using Pure DI 345–346
Circuit Breaker pattern
creating for IProductRepository 294–295
CircuitBreakerProductRepositoryDecorator class 294, 296, 302, 308, 342
client applications 7
Closed state 295
CLR (Common Language Runtime) 57, 348, 363
code blocks
registering objects with 411–412, 450–451, 482–483
removing ambiguity with 484–485
code cohesion 40
code smells 118, 127, 164, 164
Collection.Create method 456
Collection.Register method 434, 440
Command-Query Separation (CQS) 315
commands 315
Commerce.Web assembly 375
CommerceContext. DbContext 203
CommerceContext class 37, 38, 38, 48, 50, 70, 71, 75, 251, 290, 367
CommerceControllerActivator class 90, 90, 90, 91, 231, 231–231, 232, 232, 242, 243, 243, 244, 245, 252, 253, 257, 258
Common Language Runtime (CLR) 57, 348, 363
Common Service Locator (CSL) 138
compile time
coupling caused by compile-time weaving 354–354
loss of support with dynamic Interception 347–347
compile-time support 347
component elements 404
ComponentNotRegisteredException 396
components
in Autofac, multiple
selecting among multiple candidates 413–417
in Simple Injector, multiple 451–464
releasing 406–409, 440–443, 477–479
selecting from larger set 418–420, 455–457, 488–489
composability
Composer class 242, 242, 264, 264
Composite design pattern 13, 170
CompositeEventHandler<TEvent> class 424, 461, 496
CompositeLogger 275
CompositeNotificationService 171, 172, 172, 177, 422, 423, 459, 459, 492, 493, 493
Composite pattern
generic, wiring 424–425, 461–461, 496–498
non-generic, wiring 422–424, 459–460, 493–495
wiring 422–425, 459–461, 492–498
composite wrapping 177
Composition Root pattern 60, 68, 85–93
concrete classes 69
concrete types 396–397, 430–431, 469–470
concurrency bugs, by tying instances to lifetime of threads 275–278
conditional registrations 453–454
configuration
multiple implementations of same service 413–414, 452–453, 484–484
primitive Dependencies 409–411, 448–449, 480–481
Configuration as Code
configuring ContainerBuilder with 398–400
configuring containers with 433–434
configuring DI Containers with 377–379
configuring ServiceCollection with 472–473
configuration files
configuring ContainerBuilder with 403–404
configuring containers with 437–438
configuring DI Containers with 372–376
configuring instance scopes with 406–406
connectionString parameter 367
console applications, composing 213–218
Console class 16
ConsoleMessageWriter class 15, 15, 16, 16, 18, 20, 21, 25, 31
ConsoleWriter class 20
Constrained Construction anti-pattern 19, 98, 153–160
Constructor Chaining 133
Constructor Injection pattern 16, 16, 24, 53, 60, 64, 91, 93, 95–102
Constructor Over-injection code smell 164–180
ConstructorResolutionBehavior property 118, 119, 119, 119
ContainerBuilder, configuring 398–404
Container class 433
ContainerOptions class 119, 119
containers
detecting Captive Dependencies 446–446
diagnosing for lifetime problems 444–447
Content property 225
context parameter 111
Control Freak anti-pattern 88, 97, 127–136, 185
controller activators, custom
Controller class 42
ControllerTypeInfo property 397, 431
controllerType variable 397, 431, 470
converter field 102
ConvertTo method 112
coupling at compile time 354–354
CQS (Command-Query Separation) 315
create, update, and delete (CUD) operations 299
CreateCurrencyParser method 215, 216, 216–216, 216, 276, 276
CreateHomeController method 252
CreateInstance<T> method 485
CreateInstance method 155
Create method 90, 183, 186, 230, 243
CreateNew method 366
CreatePage method 228
CreateRateDisplayer method 264
CreateScope method 478
Cross-Cutting Concerns 12, 28, 31, 48, 150, 282, 348
cross-sellings 310
CSL (Common Service Locator) 138
CUD (create, update, and delete) operations 299
Currency class 217
currency conversions
adding to featured products 100–102
adding to Product Entity 112–113
CurrencyMonitoring program 262
Currency property 102
CurrencyRateDisplayer class 263, 264
Current property 146
CurrentUser property 197
CustomerServices class 107
Danish krone symbol 58
data access layers 46–47, 50, 53, 70–71, 76
database engines 5
DataContext property 220, 220, 225
DataTemplate 225
Data Transfer Objects (DTOs) 58, 182
DateTime method 146
DbContext.ChangeTracker property 203
DbContext.SaveChanges method 203
DbContext class 37, 38, 251, 262–265
DbContextOptionsBuilder 37
DbSet<T> class 175
DDD (Domain-Driven Design) 105
DDOS (Distributed Denial of Service) 292
defaultAssembly attribute 375, 403
Dependencies
injecting into MainViewModel 220–225
primitive
configuring 409–411, 448–449, 480–481
extracting to Parameter Objects 449–450, 481–481
selecting based on runtime data 187–193
dependency graphs
for analysis of missing composability 47–48
Dependency Inversion Principle (DIP) 66, 304
Dependency Lifetime, managing 238–245
Dependency property 114
deployment artifact 87
DI (Dependency Injection)
compile-time weaving aspects are unfriendly to 352–354
refactoring from Ambient Context toward 151–153
refactoring from Constrained Construction toward 157–160
refactoring from Control Freak toward 135–136
refactoring from Service Locator toward 144–144
diagnosing containers for lifetime problems 444–447
diagnostic warnings 447
DI Containers 8–8, 26, 76, 85, 261
Dictionary<TKey, TValue> class 175
DIP (Dependency Inversion Principle) 67–67–68, 68, 304, 304
DiscountedProduct class 60, 60
DisplayRates method 265
disposable Dependencies 245–255
disposables, ephemeral 247–249
disposable Transients 479
Dispose method 442
Distributed Denial of Service (DDOS) 292
Domain-Driven Design (DDD) 105
domain models, independent, building 61–69
DoSomething method 110
DRY (Don't Repeat Yourself) principle 117, 306, 342
DTOs (Data Transfer Objects) 58, 182
e-commerce applications, rebuilding 53–74
EditProductCommand property 223, 224, 225
EditProduct method 223
EditProductViewModel 248
EndpointAddress 109
EndpointAddressBuilder 109
Entity 63
enum 188
ephemeral disposables 247, 247–248, 249
Equal method 24
ErrorHandlingProductRepositoryDecorator class 297, 298
event handlers 424
executables 87
Execute method 323
extensibility 17, 19–20, 48, 118–120
factories, Control Freak through 129–133
fear, uncertainty, and doubt (FUD) 4
FeaturedProductsViewModel class 57, 57
finally statement 253
Fixture Teardown 144
folding 84
FormalGreeter 286
FUD (fear, uncertainty, and doubt) 4
general-purpose library 76
Generic Subdomain 361
generic type constraints 431
GetAllInstances method 462
GetAll method 295
GetAttributeAdapter 111
GetById method 289
GetByName method 199, 200, 201, 201
GetCurrentScope method 444
GetCurrentTime method 148
GetFeaturedProducts method 47, 48, 60, 61, 64, 75, 101, 112, 113, 113, 128, 141, 185, 270
GetInstance method 430, 431, 462
GetLogger method 151
GetRequiredService method 470, 470, 470, 476, 484
GetRoute method 188
GetService method 140, 143, 470
GetTypesToRegister method 435
GetWelcomeMessage method 147
GoBack method 223
God Class 165
God Objects 69
Greet method 285
GridView, XAML 224
Guard Clauses 16, 59, 119, 140, 167
Guard method 294
Half-Open state 295
Handle method 176
HasTierPrices property 318
HomeController class 42, 56, 95, 137, 180, 181, 232, 367
HttpContext 39
HttpContext.Response.RegisterForDispose method 230, 254
HttpContextAccessor 72
I/O operations 347
IApplicationContext 108
IAttributeAdapter method 111, 111
IAuditTrailAppender interface 195, 195, 198, 200, 201, 205, 287, 288, 289, 306
IBillingSystem 166
ICircuitBreaker interface 295, 296, 303, 353
ICommandService interface 319, 321–323, 326, 327, 382, 401, 436, 475
IComponentContext interface 419
IConstructorResolutionBehavior interface 118, 450
IControllerActivator interface 90, 90, 90, 229, 230, 397, 431
ICurrencyConverter.Exchange method 112, 113
ICurrencyConverter interface 100, 101, 101, 111, 113, 113, 214, 214
ICustomerRepository interface 107
IDisposable interface 30, 183, 183, 239, 245
IEnumerable<T> interface 175, 273–275
IEventHandler<TEvent> interface 175, 175, 176
IExchangeRateProvider interface 216, 216
IGreeter interface 285
IHttpContext interface 182, 182
IIdentity 20
IImageEffectAddIn 109
IInvocation interface 345, 345
IL (Intermediate Language) 348
ILifestyleSelectionBehavior 440
IMessageService 166
IMessageWriter.Write method 24
IMessageWriter interface 16, 16, 18, 19, 19, 20, 21, 25
implementation attribute 438
implementations, splitting 315–317
INavigationService.NavigateTo method 222
independent domain models, building 61–69
Index view markup 43
Initialize method 109, 110, 111, 222
injected streams 463
INotificationService 170, 171, 173, 179, 422, 459, 492
INotifyPropertyChanged interface 222, 223
Insert method 303
InsertProduct command 318
inside-out technique 55
InstancePerDependency 446
instance-scope attribute 406
instance scopes, configuring 405–406
Interceptor
interfaces 5
Interface Segregation Principle
Intermediate Language (IL) 348
InvalidOperationException 469
InventoryController 322
Invoke method 233
IoC (Inversion of Control) 29, 76
IOrderFulfillment interface 168, 168
IOrderRepository interface 166, 246, 247
IProductCommandServices interface 315, 315, 336
IProductManagementService interface 249
IProductQueryServices interface 336
IProductRepositoryFactory interface 130, 157, 157, 158, 183, 184, 186
IProductRepository interface 62, 63, 70, 76, 128, 130, 131, 154, 157, 183, 184, 257, 294–295, 297, 346, 367, 369, 381
IProductService interface 59, 309, 348, 367, 436, 475
IRouteAlgorithmFactory interface 189, 189, 189, 191, 192
IRouteAlgorithm interface 188, 188, 191
IRouteCalculator interface 191
isCustomerPreferred parameter 40
IsDecoratorFor method 424, 495
IServiceCollection 88
IServiceProvider 497
ISP (Interface Segregation Principle) 186, 186, 304, 304
ItemClickCommand 224
ITimeProvider interface 146, 147, 195, 329
ITypeDescriptorContext 111
IUIControlFactory interface 7
IUpdateProductReviewTotalsService 318
IUserContext interface 65, 67, 71, 101, 158, 183, 183, 198, 200, 367
IUserRepository 200, 201, 288, 288, 306
IValidationAttributeAdapterProvider interface 111
IViewModel interface 223
IVoucherRedemptionService 107, 107
JIT (Just-In-Time) compiler 348
justification argument 447
KeyedService class 424
KeyNotFoundException 141
key-value database 46
lambda expression 369
late binding 5–6–17, 18, 19, 29, 48, 154–156, 377
layering in UpdateCurrency 217–218
LazyAuditTrailAppender 205, 206
Leaky Abstractions
as parameterless factory methods 183–184
to leak Lifestyle choices to consumers 269–275
legacy applications 21
libraries
resuable 69
lifecycles of Dependencies 239–239–240, 242
Lifestyle.Singleton and Lifestyle.Transient 442
Lifestyles
Lifetime Management 30, 183, 185, 404–409, 438–447, 476–479
lifetime scopes 406
LINQ query 495
Liskov Substitution Principle 10, 21, 30, 241, 283
Locator.Reset() method 144
logging 76, 102, 149, 328, 330
LoggingMiddleware class 233
logic
implementing application logic 15–16
logical artifacts 87
LogManager.GetLogger method 151
Log method 275
long-running applications 262–265
loosely coupled code
analyzing loosely coupled implementations 74–78
rebuilding e-commerce applications 53–74
LSP (Liskov Substitution Principle)
analyzing accidental violations 323–324
fixing using generic Abstraction 324–326
Main method 15, 15, 28, 29, 86, 87, 88, 213
MainViewModel class
injecting Dependencies into 220–225
MakePreferred method 106
mapping Abstractions to concrete types 396–397, 469–470
messages, intercepting 21
messageWriter application 19
messaging 179
method calls
varying Dependency consumer on each 105–108
varying injected Dependency on each 108–109
MethodExecutionTag property 351
Method Injection pattern 53, 104–113
Microsoft.Extensions.DependencyInjection 378,
Microsoft Azure 46
Microsoft Distributed Transaction Coordinator (MSDTC) 322
MS.DI (Microsoft.Extensions.DependencyInjection)
registering difficult APIs 480–483
working with multiple components 483–498
MSDTC (Microsoft Distributed Transaction Coordinator) 322
MVC (Model View Controller) applications, for ASP.NET Core 228–234
MVVM (Model-View-ViewModel) 218, 218, 220, 220
MyApp.Services.Products namespace 323
Named method 414
Navigate method 225
NewProductViewModel 223
no operation 117
NuGet packages 441
null argument 96
NullReferenceException 11, 115, 293, 353
null value 141
Object Composition 28, 29–29, 91, 212, 385
objects
Abstractions to concrete types 430–431
resolving 395–397, 429–432, 468–471
with code blocks, registering 411–412, 450–451, 482–483
OCP (Open/Closed Principle)
fixing using Parameter Objects 317–321
IProductService violates 312–313
OnLaunched method 219
OnMethodBoundaryAspect 350, 351
OnSuccess method 351
Open/Closed Principle 14, 21, 116, 200, 297, 410
Open state 295
optional method arguments 222
Options property 119
OrderAccepted event 179
OrderApproved class 174
OrderCancelled class 174
OrderFulfillment class 175, 176
OrderService class 167, 168, 169, 246
outside-in technique 55
overloaded constructors 133–134
parallel development 17, 20–21, 49
parameterless factory methods 183–184
Parameter Objects
extracting primitive Dependencies to 449–450, 481–481
passive attributes 331
performance monitoring 328
PermittedRoleAttribute 332, 332, 333
persistence ignorance 70
per-thread Lifestyle 266
POCOs (Plain Old CLR Objects) 57, 57, 220, 220
Policy suffix 401
PostSharp tool 350
PowerShell 213
predicate value 453
price value parameter 105
primitive Dependencies
extracting to Parameter Objects 481–481
private readonly field 151
Proceed method 345
product-management rich clients, wiring up 219–225
productRepository 239
ProductRepositoryFactory class 131, 131, 132, 132
ProductRepositoryStub 141
ProductService class 40, 40, 42, 47, 64, 72, 86, 101, 101, 111, 128, 129, 133, 140–142, 143, 239, 243, 260, 272
ProductViewModel class 57
Property Injection pattern 93, 102, 114–120, 204, 204, 205
public keyword 69
readonly field 144
readonly keyword 245
reads, separating from writes 314–315
refactoring
by removing ambiguity 417–418, 455–455, 487–487
from Abstract Factory to Adapter 191–193
from Ambient Context toward DI 151–153
from Constrained Construction toward DI 157–160
from Constructor Over-injection to domain events 173–180
from Constructor Over-injection to Facade Services 168–173
from Control Freak toward DI 135–136
from Service Locator toward DI 144–144
from SRP violations to resolve Dependency cycles 200–203
RegisterAssemblyTypes method 400, 401, 402, 421, 423
RegisterConditional method 453
RegisterDecorator 383, 420–421, 457, 461
registered components 456
RegisterGenericDecorator 420, 421–422, 424
Register Resolve Release pattern 372
registrations
difficult APIs 409–412, 447–451, 480–483
objects with code blocks 411–412, 450–451, 482–483
suppressing warnings on individual 447–447
releasing components 406–409, 440–443, 477–479
Repository pattern
repository variable 128, 128, 241
Reset method 141
Resolve<T> method 397
ResolvedParameter class 415
Resolve method 88, 362, 362, 368
reusable libraries 69, 118–120
role-based security 334
RouteCalculator class 192, 243
RouteController 188, 189, 191, 232
RouteType 188
row-based security 334
runtime data, selecting Dependencies based on 187–193
Salutation class 15, 15, 16, 16, 19, 23, 24, 25
Scoped Lifestyle pattern 260–265
SecureMessageWriter class 20, 20, 20, 21, 31, 287
SecureProductRepositoryDecorator 299, 308, 331
security 19, 291, 328, 331–334
sensitive functionality 298–300
sequences
Auto-Wiring 418–418, 455–455, 487–487
wiring 417–420, 454–457, 486–489
ServiceCollection, configuring 471–476
Service Locator anti-pattern 7, 7, 8, 88, 88, 136–144, 353
ServiceProvider property 467, 478
services, weakly typed 397–397, 431–432, 470–471
SimpleDecorator class 285, 286
Simple Injector
registering difficult APIs 447–451
working with multiple components 451–464
SimpleInjector.Containe 430
SingleInstance method 405
Single Responsibility Principle
Singleton Dependencies 261
Singleton Lifestyle pattern 242, 256–258, 439
Singletons 245
Site property 118
SOLID
analysis of IProductService from perspective of 311–313
applying principles to improve design 314–327
split classes 204
splitting
SpyMessageWriter 24
SqlAuditTrailAppender 195, 195, 198, 204, 204, 205
SqlExchangeRateProvider 216, 276
SqlProductRepository 66, 67, 72, 128, 132, 132, 133, 158, 158, 158, 185, 185, 239, 243, 243, 283, 350, 367, 370, 381
SqlProductRepositoryFactory 158, 159, 159, 159
SqlProductRepositoryProxy 186, 186, 186
SqlUserByNameRetriever 201
SqlUserRepository class 197, 199, 199, 201, 204, 260
SRP (Single Responsibility Principle) 21, 28, 31, 40, 40, 40, 50, 165, 165
StackOverflowExceptions 199, 371
Startup.ConfigureServices method 90
Startup class 88, 88, 230, 230, 233, 245
stateless service 259
string argument 154
SummaryText property 57
SuppressDiagnosticWarning 447
SUT (System Under Test) 21
System.Activator class 366
System.ComponentModel.DataAnnotations 328
System.ComponentModel.Design.IDesigner 111
System.ComponentModel namespace 111
System.Data.SqlClient.SqlDataReader 462
System.DateTime.Now 27
System.IO.StreamReader class 99
System.IO.StreamWriter class 99
System.Lazy<T> class 269
System.Random 27
System.Security.Cryptography.RandomNumberGenerator 27
System.Security.Principal.WindowsIdentity class 20
System.Timers.Timer class 265
System.Transactions.TransactionScope class 322
System.Windows.Input.ICommand 220
System.Xml assembly 24
System Under Test (SUT) 21
Table Storage Service 46
TCommand argument 382
TDD (Test-Driven Development) 6, 55, 182
Temporal Coupling code smell 109–110
testability 17, 21–23, 49, 182
Test-Driven Development (TDD) 6, 55, 182
TEvent type 175
text messages, intercepting 21
third-party add-ins 5
ThreadPool.QueueUserWorkItem 276
threads 260
thread-safe in-memory Repository 257–258
three-layer diagram 35
tightly coupled code
analysis of missing composability 47–50
building tightly coupled applications 35–44
evaluating tightly coupled applications 44–47
TimeSpan 156
TitledGreeterDecorator class 286
ToEndpointAddress method 109
TrackDisposable method 252, 254
transaction aspect, applying using compile-time weaving 349–351
TransactionAttribute 349, 350, 350
TransactionCommandServiceDecorator class 321
transaction handling, applying using Abstraction 326–327
TransactionScope class 322, 351, 443
Transient Lifestyle pattern 259–260, 439
Transients, disposible 408, 479
transitivity 93
try statement 253
Type instance 19
UI (user interface) toolkits 7
UI Layer 36
UIs (user interfaces)
unauthorized access to sensitive functionality 298–300
uninterrupted power supply (UPS) 11
UnitPrice property 225
Universal Windows Programming
UpdateCurrencyCommand 217
UpdateCurrency program
building Composition Root of 215–216
updating currencies with 214–214
UpdateHasDiscountsApplied 312
UpdateHasTierPricesProperty command 310, 312, 318
UpdateProductReviewTotals 323
UpdateProductReviewTotalsService 323
UPS (uninterrupted power supply) 11
Uri property 109
Use extension method 233
userContext variable 198
user interface (UI) toolkits 7
user interfaces
UserMailAddressChanged even 203
userRepository variable 198
UserService class 199
using statement 249
uto-Registered Abstractions 458
UWP (Universal Windows Programming) applications 87
Validate method 247
validateScopes 469
valueAccessor delegate 415
Value property 270
violations
of SRP
Dependency cycle caused by 195–198
refactoring from to resolve Dependency Cycle 200–203
Visual Studio 5
Volatile Dependencies 26–27, 50, 53, 127, 355–355
WCF (Windows Communication Foundation) 247
WcfProductRepository class 248, 249, 294, 297
web-based UI 76
WelcomeMessageGenerator 151
whenDone action 222
Where method 401
Windows Communication Foundation (WCF) 247
Windows Presentation Foundation (WPF) 45
wiring
Composites 422–425, 459–461, 492–498
Decorators 420–422, 457–459, 489–492
product-management rich clients 219–225
sequences 417–420, 454–457, 486–489
WithParameter method 412, 415, 419, 425
WPF applications 87
WPF-based UI 76
wrapping, composite 177
writer instance 14
writes, separating from reads 314–315
WrittenMessage property 24
XmlProductRepository 156
XmlReader argument 156
XmlWriter 24
YAGNI principle 55
3.135.187.210