当您在容器中有多个实现时,如何让Castle Windsor在运行时选择正确的接口植入.
例如,假设我有一个名为IExamCalc的简单界面,它可以计算出某人在该考试中的表现.
不,我们有几个像这样的实现,例如,
public interface IExamCalc
{
int CalculateMark(ExamAnswers examAnswers)
}
public class WritenExam : IExamCalc
{
public int CalculateMark(ExamAnswers examAnswers)
{
return 4;
}
}
public class OralExam : IExamCalc
{
public int CalculateMark(ExamAnswers examAnswers)
{
return 8;
}
}
public class ExamMarkService
{
private IExamCalc _examCalc;
public ExamMarkService(IExamCalc examCalc)
{
_examCalc = examCalc;
}
public int[] CalculateExamMarks(ExamAnswers[] examAnswers)
{
IList<int> marks = new List<int>;
foreach(ExamAnswers examanswer in examaAnswers)
{
marks.Add(_examCalc.CalculateMark);
}
}
}
Run Code Online (Sandbox Code Playgroud)
假设通过Windor恢复了ExamMarkService如何确保在构造函数中注入正确的实现,这是多租户问题的一个例子吗?
希望一切都有所作为
科林G.
我不想让用户安装Google Gears,这样我就可以向他展示他猜测的位置.有没有办法在不使用Google Gears的情况下获取位置?
我找到了http://www.wipmania.com/de/blog/google-geolocation-api/,但它没有提供示例.
<?php
class Box {
var $contents;
function Box($contents) {
$this->contents = $contents;
}
function get_whats_inside() {
return $this->contents;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我正在阅读OO教程.我熟悉PHP和OO的概念,但大多数时候它仍然是一场艰难的斗争!但是,上面的代码返回错误"Unexpected&on line 7".我发现其他任何人都没有遇到过本教程的问题.我用PHP版本5.2.5运行MAMP.有人有主意吗?
如何在运行时以各种方式修改propertygrid?我希望能够添加和删除属性并添加"动态类型",我的意思是使用TypeConverter导致在propertygrid中生成运行时生成的下拉列表.
我实际上已经能够做这两件事(添加/删除属性和添加动态类型)但不能同时单独使用.
为了实现在运行时添加和删除属性的支持,我使用了这个代码项目文章并稍微修改了代码以支持不同的类型(不仅仅是字符串).
private System.Windows.Forms.PropertyGrid propertyGrid1;
private CustomClass myProperties = new CustomClass();
public Form1()
{
InitializeComponent();
myProperties.Add(new CustomProperty("Name", "Sven", typeof(string), false, true));
myProperties.Add(new CustomProperty("MyBool", "True", typeof(bool), false, true));
myProperties.Add(new CustomProperty("CaptionPosition", "Top", typeof(CaptionPosition), false, true));
myProperties.Add(new CustomProperty("Custom", "", typeof(StatesList), false, true)); //<-- doesn't work
}
/// <summary>
/// CustomClass (Which is binding to property grid)
/// </summary>
public class CustomClass: CollectionBase,ICustomTypeDescriptor
{
/// <summary>
/// Add CustomProperty to Collectionbase List
/// </summary>
/// <param name="Value"></param> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用powershell配置帐户凭据,但我需要授予帐户"作为服务登录"权限才能使其正常工作.我怎么能在PowerShell中做到这一点?
如何从使用包的项目中查找和删除未使用的Delphi运行时包?
我有一个由几个包组成的Delphi项目,在需要的部分包中列出了几个Borland/3rd party软件包(rtl.dcp,vcl.dcp等)我知道我需要它们中的大多数,但是有我知道我不需要那些随着时间的推移,可能一个组件使用它们一次,但后来该组件被删除,或者可能是我测试代码.
我如何找出哪些是必需的,哪些不是?如果不需要它们,它们是否仍需要与最终应用程序一起分发,或者对应用程序的大小/内存要求有任何影响?
我试图尽可能简化流程.
我最近在部署Windows服务时遇到了问题.四台计算机没有造成任何问题,但在第五台计算机上由于异常而导致启动服务的任何尝试都失败了.异常堆栈跟踪被写入事件日志,因此我应该很容易确定原因:
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("Starting service", EventLogEntryType.Information);
try
{
//...
base.OnStart(args);
}
catch (Exception ex)
{
EventLog.WriteEntry("Service can not start. Stack trace:" + ex.StackTrace, EventLogEntryType.Error);
Stop();
return;
}
EventLog.WriteEntry("Service started", EventLogEntryType.Information);
}
Run Code Online (Sandbox Code Playgroud)
但是,唉,没有任何信息写入日志.我终于将它追溯到正在编写的第一个日志条目.它引发了一个异常,因为应用程序事件日志已满,包含最近的条目,并且配置为仅覆盖超过7天的条目.
考虑到我无法更改应用程序事件日志的配置,写入事件日志的最佳做法是什么?
我应该总是放入EventLog.WriteEntry一个try块,如果是,我应该如何处理异常(将它写入事件日志可能是一个坏主意),我应该检查我的OnStart方法中的事件日志状态,还是你有更好的建议?
我有一个以空格分隔的文件名列表,其中文件名中的空格以'\'为前缀
例如"first\file second\file"
如何让我的正则表达式匹配每个文件名?
是否有Windows API函数允许读取当前密码策略是什么?例如,最小长度,复杂性等.
如果没有阅读,有没有办法以编程方式验证策略的密码?
.net ×2
c# ×1
delphi ×1
event-log ×1
geolocation ×1
google-gears ×1
google-maps ×1
packages ×1
php ×1
powershell ×1
propertygrid ×1
regex ×1
security ×1
winapi ×1
windows ×1
winforms ×1