Book Library
Book Library
Introduction
The Book Library sample application shows how to use the WPF Application Framework (WAF) in a data oriented application.
This sample application is part of the WPF Application Framework (WAF) download.
Highlights
Layered Architecture and usage of the Model-View-ViewModel pattern (MVVM). Usage of an Extension. This Extension is optional and can be deactivated via configuration file.
cmp BookLibrary Waf.BookLibrary
Extension
Library.Presentation
Reporting.Presentation
Library.Applications
Reporting.Applications
Library.Domain
The Entity Framework is used in combination with a SQL Server Compact Edition database.
The entities provide validation rules which are reflected on the user interface.
The data can be sorted and filtered in the DataGrid. Create a new Email when the user clicks on an email address in the BookLibrary application. Create reports via the WPF FlowDocument infrastructure.
All layers are unit tested. The Domain and Application layers are completely tested except the entity framework related code. The Presentation layer is partly tested. Unit test code coverage:
Project Structure
BookLibrary.Library BookLibrary.Reporting The main application. An extension which provides the Reporting feature.
BookLibrary.Library.Presentation 1. 2. 3. 4. 5. Converters DesignData Resources Services Views Value converters Design time support ResourceDictionaries, Images, Icons UI service implementations WPF Views (Windows, UserControls)
BookLibrary.Library.Applications 1. 2. 3. 4. 5. Controllers DataModels Services ViewModels Views Use case controllers DataModels for DataTemplates Interfaces and implementation of services ViewModels for the Views Interfaces for the Views
BookLibrary.Library.Domain 1. (Root) 2. Resources Entity Data Model and partial classes for the Entities Database file
BookLibrary.Reporting.Presentation 1. 2. 3. 4. Controls DesignData Reports Views Custom WPF Controls Design time support WPF Reports (FlowDocuments) WPF Views (Windows, UserControls)
BookLibrary.Reporting.Applications 6. 7. 8. 9. 10. Controllers DataModels Reports ViewModels Views Use case controllers DataModels for DataTemplates Interfaces for the Reports ViewModels for the Views Interfaces for the Views
Domain Layer
BookLibrary.Library.Domain\BookLibraryModel.edmx
Features
Reporting Extension
The BookLibrary application comes with the Reporting extension. When it is activated then it extends the application by the reporting feature. The activation is done in the BookLibrary.exe.config file or during development in the App.config file. BookLibrary.Library.Presentation/App.config (see ModuleAssemblies) In the config file the extension assemblies are added. The bootstrapping code was adapted to load the extension assemblies as well. BookLibrary.Library.Presentation/App.xaml.cs (see OnStartup method) The extension integrates its feature via the ShellService into the user interface. BookLibrary.Reporting.Applications/Controllers/ModuleController.cs (see Initialize method) The TabItem Reporting is only shown when the Reporting extension is loaded. Furthermore, the Reporting view is loaded on demand when the Tab is shown the first time (Better startup performance). BookLibrary.Library.Presentation/Views/ShellWindow.xaml (see TabItem with Header=Reporting) Note: All projects of the BookLibrary application build into the same Output directory. This way the extension assemblies are available for the application although they are not referenced.
WAF provides the DataErrorInfoSupport class which connects the DataAnnotations validation with the IDataErrorInfo interface. BookLibrary.Library.Domain/Person.cs (see Error and this[] property) Because entity classes are partial classes generated by the Entity Framework, it's not possible to write the validation attributes directly to the properties. A workaround is to introduce an interface with these properties and specify the attributes there. BookLibrary.Library.Domain/Person.cs (see IPerson interface) The MetadataType attribute defines the association between the entity class and the interface. BookLibrary.Library.Domain/Person.cs (see Person class) Enable the DataAnnotations infrastructure to use the MetadataType information. BookLibrary.Library.Domain/BookLibraryEntities.cs (see static constructor)
The WAF ValidationHelper class is used to track the errors in the UI. These errors are synchronized with the IsValid flag of the ViewModel.
waf:ValidationHelper.IsEnabled="true" waf:ValidationHelper.IsValid= "{Binding IsValid, Mode=OneWayToSource}"
These attached properties are used on the Window element. BookLibrary.Library.Presentation/Views/ShellWindow.xaml The IsValid flag is used to enable/disable the Save command. BookLibrary.Library.Applications/Controllers/EntityController.cs (see CanSave method)
10
11
12