-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
translate event aggregator, dependency injection etc.
- Loading branch information
Showing
26 changed files
with
195 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# Prism 中文文档 | ||
|
||
> [Prism 官方文档](https://docs.prismlibrary.com/docs/)的中文版本。 | ||
## Prism 概述 | ||
Prism 是一个用于构建松耦合、可维护且可测试的 XAML 应用程序的框架,适用于 WPF、.NET MAUI、Uno平台和 Xamarin Forms。 | ||
|
||
# 概述 | ||
点击[Prism简介](introduction.md)开始阅读。 | ||
## 项目简介 | ||
> [Prism 官方文档](https://docs.prismlibrary.com/docs/) 的中文版本。 | ||
## 在线阅读地址 | ||
https://corey212.github.io/Prism-Documentation-zh/ | ||
|
||
# 快速开始 | ||
点击 [Prism简介](index.md) 开始阅读。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
# Dependency Injection with Prism | ||
# 使用 Prism 进行依赖注入 | ||
|
||
Prism has always been built around Dependency Injection. This helps you to architect apps that are maintainable and testable and help you reduce or eliminate your dependence on Static and circular references. Prior to Prism 7, dependency injection with Prism was focused around various containers that were implemented for use with Prism. This led to a number of issues including that while docs may have been written showing you how to do something with one container they did not necessarily reflect the appropriate API to use for the container that you were using for your application. | ||
Prism 始终围绕依赖注入构建。这有助于构建可维护和可测试的应用,并帮助您减少或消除对静态和循环引用的依赖。在 Prism 7 之前,Prism 的依赖注入主要集中在与 Prism 一起使用的各种容器上。这导致了许多问题,包括虽然可能已经编写了文档,向您展示了如何使用一个容器执行某些操作,但它们不一定反映用于您用于应用程序的容器的适当 API。 | ||
|
||
Prism 7 introduced several new interfaces for abstracting what Prism requires for dependency injection. This has several benefits as you might imagine including: | ||
Prism 7 引入了几个新的接口,用于抽象 Prism 对依赖注入所需的内容。正如您可能想象的那样,这有几个好处,包括: | ||
|
||
- Docs showing how to do something in Prism will always show you what you need to do without any concern for which dependency injection container you are using. | ||
- This greatly simplified what needed to be added to any container specific package. In the case of Prism.Forms this reduces each container specific project 3 classes: `PrismApplication`, an implementation of `IContainerExtension` and an extension class to retrieve the underlying container should you feel the need to access it for one of it's API's that is not implemented by Prism. | ||
- 展示如何在 Prism 中执行某些操作的文档将始终向您显示您需要执行的操作,而无需担心您正在使用的依赖项注入容器。 | ||
- 这大大简化了需要添加到任何容器特定包的内容。在 Prism.Forms 的情况下,这将每个特定于容器的项目减少 3 个类: `PrismApplication` 、一个实现 `IContainerExtension` 和一个扩展类,用于检索底层容器,如果您觉得需要访问它,以获得 Prism 未实现的 API 之一。 | ||
|
||
In Prism 9, the Prism Ioc layer has been removed from the Prism.Core and now ships independently from Prism. This makes it easier for us to share the container implementation across all supported Prism platforms (WPF, Uno Platform, .NET MAUI, etc). Additional work has been done in Prism 9 to also give the containers better integration with Microsoft.Extensions.DependencyInjection and provide better support for Container Scoping scenarios some of which are used extensively by Prism.Maui. | ||
在 Prism 9 中,Prism Ioc 层已从 Prism.Core 中删除,现在独立于 Prism 发货。这使我们可以更轻松地在所有受支持的 Prism 平台(WPF、Uno 平台、.NET MAUI 等)之间共享容器实现。在 Prism 9 中还完成了其他工作,以便容器更好地与 Microsoft.Extensions.DependencyInjection 集成,并为容器范围方案提供更好的支持,其中一些方案被 Prism.Maui 广泛使用。 | ||
|
||
## Using Microsoft's IServiceCollection | ||
## 使用 Microsoft 的 IServiceCollection | ||
|
||
Prism 9.0 has separated the Container implementations from the main Prism repo. This allows us to ship and to share the containers across all platforms without any specific code coupling to the Prism.Core. In the updated Prism 9.0 implementations support has been added for Microsoft's IServiceCollection. This helps Prism better support .NET MAUI applications and the IHostBuilder approach used by the Uno.Extensions. It is important to consider that when using Registration Extensions from various Microsoft libraries, these will have been tailored to use for Web Applications. For example if using EntityFrameworkCore the default Lifetime of the DbContext will be set to Scoped. For most Prism applications you will likely want to set this to be Transient as a Singleton could cause DbAccess issues if different ViewModels or Services are accessing the database at the same time. Be sure to spend some time evaluating any prebuilt extension methods for registering services so that you can be sure that the service will have an appropriate lifetime for your application. | ||
Prism 9.0 已将容器实现与主 Prism 存储库分开。这使我们能够在所有平台上交付和共享容器,而无需与 Prism.Core 进行任何特定的代码耦合。在更新的 Prism 9.0 实现中,添加了对 Microsoft 的 IServiceCollection 的支持。这有助于 Prism 更好地支持 .NET MAUI 应用程序和 Uno.Extensions 使用的 IHostBuilder 方法。请务必考虑,在使用各种 Microsoft 库中的注册扩展时,这些扩展将针对 Web 应用程序进行定制。例如,如果使用 EntityFrameworkCore,则 DbContext 的默认生存期将设置为 Scoped。对于大多数 Prism 应用程序,您可能希望将其设置为瞬态,因为如果不同的 ViewModel 或服务同时访问数据库,则 Singleton 可能会导致 DbAccess 问题。请务必花一些时间评估用于注册服务的任何预生成扩展方法,以便确保服务具有适合应用程序的生存期。 | ||
|
||
## Containers | ||
## 容器 | ||
|
||
The Prism team ships several DI container implementations for the Prism IoC abstractions. | ||
Prism 团队为 Prism IoC 抽象提供了多个 DI 容器实现。 | ||
|
||
| Container | Availability | Notes | | ||
| 容器 | 获取 | 说明 | | ||
|:---------:|:------------:|:-----:| | ||
| DryIoc | NuGet.org | Supported across all targets | | ||
| Grace | Commercial Plus | | | ||
| Microsoft | Commercial Plus | | | ||
| Unity | NuGet.org | Legacy support for Xamarin.Forms and WPF only | | ||
|
||
> [!NOTE] | ||
> While the DryIoc and Unity Container's are available on NuGet.org they are still subject to the Prism License. You should have a valid license for Prism. | ||
?> 虽然 DryIoc 和 Unity 容器在 NuGet.org 上可用,但它们仍受 Prism 许可证的约束。您应该拥有 Prism 的有效许可证。 | ||
|
||
## Next Steps | ||
|
||
- Learn how to [Register Services](xref:DependencyInjection.RegisterServices) | ||
- Learn how to [Register Pages for Navigation](xref:Platforms.XamarinForms.Navigation.Basics) ***(Xamarin Specific)*** | ||
- Learn how to [Register Platform Specific Services](xref:DependencyInjection.IPlatformInitializer) ***(Xamarin Specific - Legacy)*** | ||
- [Microsoft.Extensions.DependencyInjection (Supplement)](xref:DependencyInjection.Supplement) | ||
- 了解如何 [注册服务](xref:DependencyInjection.RegisterServices) | ||
- 了解如何 [注册用于导航的页面(特定于 Xamarin)](xref:Platforms.XamarinForms.Navigation.Basics) ***(Xamarin Specific)*** | ||
- 了解如何 [注册特定于平台的服务(Xamarin 特定 - 旧版)](xref:DependencyInjection.IPlatformInitializer) ***(Xamarin Specific - Legacy)*** | ||
- [Microsoft.Extensions.DependencyInjection(补充)](xref:DependencyInjection.Supplement) | ||
<!-- - Learn how to [Add a Custom Container](xref:DependencyInjection.AddCustomContainer) --> | ||
- Learn more about the Prism Container Extensions and working with Shiny in the [Appendix](xref:DependencyInjection.Appendix) | ||
- 在[附录](xref:DependencyInjection.Appendix)中了解有关 Prism 容器扩展和使用 Shiny 的更多信息 |
Oops, something went wrong.