Arrrgh!我把头发拉过来.我一直试图使用IoC容器一点点,所有看起来都很好和花花公子,直到你遇到一些你认为非常基本的问题,比如将参数传递给构造函数.
假设我的某个类有一个可以由IoC解决的引用类和可以在运行时解析的值类型(或其他类型):
public NFLFeedUnitOfWork(NFLFileType fileType, object feed, IConverterMappings<NFLFileType> nflConverterMappings, IDbContext context)
: base(fileType, feed, nflConverterMappings, context, ContextType.NFL)
{
//new NFLContext(connstringname, setAutoDetectChanges)
}
Run Code Online (Sandbox Code Playgroud)
在这个特定的例子中,我传入Enum(NFLFileType),对象实例,2个接口参数,并将一个额外的硬编码属性传入基础构造函数(ContextType.NFL)
如何以所有神的名义在任何IoC容器中执行此操作?
问题实际上是双重的:
1.)如何传入仅在运行时已知的对象?比如说,目前调用代码看起来像这样:
protected override IFeedUnitOfWork GetUnitOfWork(NFLFileType fileType, object feed, string connectionString)
{
return new NFLFeedUnitOfWork(fileType, feed, new NFLConverterMappings(), new NFLContext(connectionString));
}
Run Code Online (Sandbox Code Playgroud)
如何将此代码转换为使用IoC?也许是这样的?
protected override IFeedUnitOfWork GetUnitOfWork(NFLFileType fileType, object feed, string connectionString)
{
return IFLFeedUnitOfWork(fileType, feed);
}
Run Code Online (Sandbox Code Playgroud)
最后2个参数自动解决的地方,我自己提供的第1个2个参数?
2.)如何使用IoC将Enum,对象,值类型传递给构造函数?(或者在这个特定的例子中可能不使用它?)
无论如何,非常感谢任何帮助,特别是在第一点.我目前正在使用Unity,但任何其他IoC容器也都可以.
我也不想将IoC容器传入代码,我只想在顶层的一个地方指定它.
如何可以无缝地可靠地连续播放多个视频?由于播放2个视频之间存在小的暂停或闪烁.
在我的特定示例中,我有3个视频.我需要一个接一个地无缝地播放所有3个,我还需要循环中间视频任意次数(比如说2或3).所有这些都需要在不同的浏览器中无缝且一致地发生.
我一直在尝试月球下的所有东西,从在视频结束时开始视频播放,到使用几个视频标签以及隐藏和替换它们,我甚至尝试在Flash中实现这一点,但是唉没有任何作用,并且在当前发生同样的问题Flash也是如此.
我已经多次看过这个(或类似的)问题,但我还没有看到可靠的解决方案.
有谁知道解决这个问题?
如何从上下文菜单中显示模态对话框?
我可以在上下文菜单中显示一个新窗口,该窗口在自己的选项卡中打开:
var menuItem = {
"id": "rateMenu",
"title": "Rate Item",
"contexts": ["all"],
}
chrome.contextMenus.create(menuItem);
chrome.contextMenus.onClicked.addListener(function (clickData) {
open('index.html');
});
Run Code Online (Sandbox Code Playgroud)
我也知道如何在页面本身上使用bootstrap(例如)显示模态对话框:
$('#myModal').modal({
backdrop: 'static',
keyboard: false
})
Run Code Online (Sandbox Code Playgroud)
在这种特殊情况下,我想显示一个模态对话框,除非按下"关闭"按钮,否则无法关闭.
但是,我不知道如何直接从上下文菜单中显示模态弹出窗口.
有谁知道如何实现这一目标?
谢谢!
在解决方案中组织单元测试和集成测试的最佳实践是什么?
我倾向于每个实际项目有 2 个测试项目,命名如ProjectName.Tests.Unit和ProjectName.Tests.Integration,但是看起来每个代码项目会有太多测试项目。然而,另一种方法是将所有测试放在两个测试项目中,这似乎更糟糕。
有人可以评论一下您(将)如何在解决方案中构建单元测试和集成测试吗?
考虑这个代码(来自这里):
父组件:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
template: `<app-child (valueChange)='displayCounter($event)'></app-child>`
})
export class AppComponent implements OnInit {
ngOnInit() {
}
displayCounter(count) {
console.log(count);
}
}
Run Code Online (Sandbox Code Playgroud)
子组件:
import { Component, EventEmitter, Output } from '@angular/core';
@Component({
selector: 'app-child',
template: `<button class='btn btn-primary' (click)="valueChanged()">Click me</button> `
})
export class AppChildComponent {
@Output() valueChange = new EventEmitter();
Counter = 0;
valueChanged() { // You can give any function name
this.counter = this.counter + 1;
this.valueChange.emit(this.counter);
} …Run Code Online (Sandbox Code Playgroud)