至于我的理解,写作(单元)可测试代码的一部分,构造函数不应该在构造函数中做真正的工作而只分配字段.到目前为止,这非常有效.但我遇到了一个问题,我不确定解决问题的最佳方法是什么.请参阅下面的代码示例.
class SomeClass
{
private IClassWithEvent classWithEvent;
public SomeClass(IClassWithEvent classWithEvent)
{
this.classWithEvent = classWithEvent;
// (1) attach event handler in ctor.
this.classWithEvent.Event += OnEvent;
}
public void ActivateEventHandling()
{
// (2) attach event handler in method
this.classWithEvent.Event += OnEvent;
}
private void OnEvent(object sender, EventArgs args)
{
}
}
Run Code Online (Sandbox Code Playgroud)
对我来说选项(1)听起来不错,但构造函数应该只分配字段.选项(2)感觉有点"太多".
任何帮助表示赞赏.
我希望我的MSI包将值InstallLocation写入HKEY_LOCAL_MACHINE\SOFTWARE\\(Wow6432Node)\Microsoft\Windows\CurrentVersion\Uninstall\\(GUID).您还应该在"添加/删除程序"控制面板(列Location)中看到此值.
要通过WiX设置此值,我读到应该通过自定义操作设置属性ARPINSTALLLOCATION.我减少<Product>到最低限度.这是它的样子:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*"
Name="MyApplication"
Language="1033"
Version="!(bind.FileVersion.MyApplication.exe)"
Manufacturer="Me"
UpgradeCode="db37f5dc-68c5-46ee-bbdf-704ff68b70db">
<Package InstallerVersion="400" Compressed="yes" InstallScope="perMachine" Languages="0" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<!-- use SetProperty as suggested by Rolo -->
<SetProperty Id="ARPINSTALLLOCATION" Value="[INSTALLDIR]" After="CostFinalize" />
<Feature Id="ProductFeature" Title="MyApplication" Level="1">
<ComponentGroupRef Id="MyApplication.Files.AllRequired" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="MyApplication" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="MyApplication.Files.AllRequired">
<Component …Run Code Online (Sandbox Code Playgroud)