我想使用Castle Windsor在WebApi应用程序中实现依赖注入.我有以下示例代码 -
界面 -
public interface IWatch
{
{
DateTime GetTime();
}
}
Run Code Online (Sandbox Code Playgroud)
以下Watch类实现了IWatch接口 -
public class Watch:IWatch
{
public DateTime GetTime()
{
return DateTime.Now;
}
}
Run Code Online (Sandbox Code Playgroud)
WebApi控制器 - WatchController如下 -
public class WatchController : ApiController
{
private readonly IWatch _watch;
public WatchController()
{
_watch = new Watch();
}
//http://localhost:48036/api/Watch
public string Get()
{
var message = string.Format("The current time on the server is: {0}", _watch.GetTime());
return message;
}
}
Run Code Online (Sandbox Code Playgroud)
目前我在WatchController构造函数中使用Watch启动IWatch对象.我想删除使用Windsor Castle依赖注入原理在构造函数中初始化IWatch的依赖性.
在这种WebApi的情况下,任何人都可以为我提供实现依赖注入的步骤吗?提前致谢!
我遵循数据表结构 -
User ID | User Name | Manager ID
-------------------------------------
1 | ABD | 2
2 | BCD | NULL
3 | KUM | 4
4 | POC | NULL
5 | OJM | 2
Run Code Online (Sandbox Code Playgroud)
在上表中,用户ID - 2是用户ID的管理员 - 1,5类似用户ID - 4是用户ID - 3的管理员.
如何创建自我关系以显示Manager - > Users的层次结构细节?
我想模拟对象返回的索引器属性。我正在使用 NSubstitute 进行模拟。我有以下场景。在示例中,我想在从 IFeedData.GetFeedData 返回时模拟索引器属性this[string symbolName]
public class FeedEntity
{
private SymbolData _symbolData;
public string Symbol { get; set; }
public SymbolData this[string symbolName]
{
get //Search Data into Actual Feed and returns relevent data for Symbol
{
if (_symbolData != null)
{
_symbolData = new SymbolData//Just Created For Sample Purpose
{
TraderName = "TestTrader",
BrokerName = "TestBroker"
};
}
return _symbolData;
}
set
{
_symbolData = value;
}
}
}
public class SymbolData
{
public string TraderName { …Run Code Online (Sandbox Code Playgroud) 我正在使用highcharts.js来构建水平条形图。它的工作正常,但默认情况下工具提示显示为水平,因此我希望工具提示位置为垂直而不是水平。
有可能实现这一目标吗?任何帮助表示赞赏!JSFiddle- 示例
样例代码:
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'bar'
},
title: {
text: 'Stacked bar chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -100,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme …Run Code Online (Sandbox Code Playgroud)