小编Ana*_*nov的帖子

从ErrorTemplate访问Validation.Errors

我在网格中有一个BindingGroup:

<Grid x:Name="?????????????" DataContext="{Binding Source={StaticResource ????????}}"
    Grid.RowSpan="1" Grid.Row="1" HorizontalAlignment="Center">
  <Grid.BindingGroup>
    <BindingGroup NotifyOnValidationError="True">
      <BindingGroup.ValidationRules>
        <??:??????????? ValidationStep="ConvertedProposedValue" />
      </BindingGroup.ValidationRules>
    </BindingGroup>
  </Grid.BindingGroup>
  <Grid.Style>
    <Style>
      <Setter Property="Validation.ErrorTemplate" Value="{StaticResource BindingGroup??????}" />
    </Style>
  </Grid.Style>
  ...
Run Code Online (Sandbox Code Playgroud)

我的网格有一个ErrorTemplate:

<ControlTemplate x:Key="BindingGroup??????">
  <Border BorderBrush="Blue" BorderThickness="2">
    <StackPanel>
      <Label Content="My BindingGroup Error should be here!"></Label>
      <AdornedElementPlaceholder />
    </StackPanel>
  </Border>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

我想从我的ControlTemplate访问Validation.Errors [0] .ErrorContent以在我的标签中显示它。可能吗?请你帮助我好吗?

validation wpf xaml controltemplate errortemplate

5
推荐指数
1
解决办法
477
查看次数

为什么 DBContext Find 方法需要验证缓存以检测仍待提交到数据库的更改?

\n

默认情况下,调用此方法 [DBContext.Find] 将触发对象缓存的验证,以检测仍待提交到数据库的更改

\n
\n\n

实体框架 5 的性能注意事项

\n\n

我根本不明白:为什么 Find 方法需要检测未提交到数据库的更改?为什么这对它有用呢?使此方法验证这些更改的缓存的原因是什么?

\n\n

Find 方法返回实体的缓存副本 - 无论它是否保存到数据库。如果缓存中不存在该实体,则 Find 方法对数据库执行查询,获取该实体并将其附加到缓存,然后将其返回给调用者。为什么需要检测实体是否已经提交到数据库或尚未提交?

\n\n

请新人解释一下!

\n\n

PS 请原谅我的英语,这不是我的母语!

\n\n

更新。Find 方法调用 DetectChanges 方法来检测更改。如果 AutoDetectChangesEnabled = false,则不会调用 DetectChanges。当 AutoDetectChangesEnabled 为 true 或 false 时调用 Find 方法有什么区别(除了性能下降)?\n我已经发现调用 Add 方法时的差异,这里是:http://ilmatte.wordpress.com/2013/01/01/entity-framework-code-first-always-disable-autodetectchanges-when- importing-data/ ,\xc2\xa0\xe2\x80\x94 但我仍然无法理解调用 Find 时有什么区别?

\n

.net performance entity-framework find

5
推荐指数
0
解决办法
582
查看次数

如何编写遵循依赖注入模式的工厂?

我是 DI 模式的新手,因此,这是我的问题。

编辑 4 月 11 日

如果我有某个工厂实现了一些业务逻辑,并在运行时根据给定的输入参数创建了它的主要对象及其依赖项,我应该如何实现它才能不破坏 DI 原则?(它是否应该避免直接调用 new 运算符来实例化其主要对象(由该工厂生产)及其依赖项,不是吗?)

(4 月 11 日编辑结束)

考虑以下 CarFactory 示例:

interface IEngine {}

class RegularEngine implements IEngine {}

class AdvancedEngine implements IEngine {}

class Car
{
    private $engine;

    public function __construct(IEngine $engine)
    {
        $this->engine = $engine;
    }
}

class CarFactory
{
    public function __invoke(bool $isForVipCustomer = false): Car
    {
        // @todo Here, CarFactory creates different Enginges and a Car,
        // but they should be injected instead?
        $engine = $isForVipCustomer ? …
Run Code Online (Sandbox Code Playgroud)

php design-patterns factory dependency-injection

1
推荐指数
1
解决办法
1394
查看次数