我有现有的项目,它使用AutoFac作为IoC.
在注册码中我有这些线:
var resolver = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(resolver));
config.DependencyResolver = new AutofacWebApiDependencyResolver(resolver);
Run Code Online (Sandbox Code Playgroud)
所以我的问题是DependencyResolver.SetResolver和之间的区别是什么HttpConfiguration.DependecyResolver?我为什么要指定它们?
假设我有这样的界面和具体实现
public interface IMyInterface<T>
{
T My();
}
public class MyConcrete : IMyInterface<string>
{
public string My()
{
return string.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我创建了MyConcrete实现strings,我可以有一个更具体的实现int.那没关系.但是,让我们说,我想做同样的事情,但使用通用方法,所以我有
public interface IMyInterface2
{
T My<T>();
}
public class MyConcrete2 : IMyInterface2
{
public string My<string>()
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
所以我有相同的IMyInterface2,但它通过定义通用行为T My<T>().在我的具体类中,我想实现My行为,但对于具体的数据类型 - string.但C#不允许我这样做.
我的问题是为什么我不能这样做?换句话说,如果我可以创建MyInterface<T>as的具体实现MyClass : MyInterface<string>并在此时停止泛化,为什么我不能用泛型方法做到这一点 - T My<T>()?
假设我有这样的结构
public class Form
{
#region Public Properties
public List<Field> Fields { get; set; }
public string Id { get; set; }
public string Name { get; set; }
public string Version { get; set; }
public int Revision { get; set; }
#endregion
}
Run Code Online (Sandbox Code Playgroud)
所以Form该类包含字段列表,假设字段本身用这种结构表示
public class Field
{
#region Public Properties
public string DisplayName { get; set; }
public List<Field> Fields { get; set; }
public string Id { get; set; }
public FieldKind Type { …Run Code Online (Sandbox Code Playgroud) 我们正在移植建模应用程序,它使用IronPython脚本在建模过程中进行自定义操作.现有应用程序在单独的线程中执行每个Python脚本,并为此使用协作模型.现在我们想将它移植到TPL,但首先我们要测量上下文切换.基本上,我们现在拥有的:
Task队列Task队列都执行一个IronPython脚本Task(IronPython执行)到等待状态我们想做什么:
Tasks队列Task我们尝试执行它Task我们检查它是否处于等待状态.如果是这样,我们将其唤醒并尝试执行.TaskTask每秒可执行的数量我真的不知道合作多任务是什么?我们在考虑定制TaskScheduler,这是好方法吗?还是有人知道更好的解决方案?
谢谢.
更新:
好的,例如,我有这样的代码:
public class CooperativeScheduler : TaskScheduler, IDisposable
{
private BlockingCollection<Task> _tasks;
private Thread _thread;
private Task _currentTask;
public CooperativeScheduler()
{
this._tasks = new BlockingCollection<Task>();
this._thread = new Thread(() =>
{
foreach (Task task in this._tasks.GetConsumingEnumerable())
{
this._currentTask = task;
TryExecuteTask(this._currentTask);
}
}
);
this._thread.Name = "Cooperative scheduler thread";
this._thread.Start();
} …Run Code Online (Sandbox Code Playgroud) 编辑:是否可以将实体框架与Windows Azure开发存储服务一起使用?如何?
谢谢.
如何检测屏幕阅读器是否正在运行(JAWS)?
正如我在.NET 4的理解,我们可以使用AutomationInteropProvider.ClientsAreListening从System.Windows.Automation.Provider命名空间,但如果我必须做的.NET 2.0是什么?
我试图检查ClientsAreListening源代码,它RawUiaClientsAreListening从UIAutomationCore.dll库调用外部方法.
您对如何在.NET 2.0中实现JAWS检测有任何想法吗?
c# accessibility screen-readers ui-automation jaws-screen-reader
我有一个简单的页面与Kendo TabStrip里面
<div id="main-view" class="k-content">
@(Html.Kendo().TabStrip()
.Name("main-view-tabstrip")
.Items(tabstrip =>
{
tabstrip.Add().Text("My Notices").LoadContentFrom("MyNotices", "Notice").Selected(true);
}))
</div>
Run Code Online (Sandbox Code Playgroud)
它根据需要为我加载内容,查询NoticeController.NoticeController有MyNotices回复我的行动PartialView.
public PartialViewResult MyNotices()
{
// put some values into ViewData
return PartialView();
}
Run Code Online (Sandbox Code Playgroud)
PartialView itseld看起来像这样:
<div style="margin: 20px; height: 700px;">
@(Html.Kendo().Grid<NoticeViewModel>(Model)
.HtmlAttributes(new { @class = "fullScreen" })
.Name("NoticesList")
.Columns(columns =>
{
columns.Bound(x => x.UniqueId).Title("UniqueId");
columns.Bound(x => x.FormName).Title("Form");
columns.Bound(x => x.Revision).Title("Revision");
columns.Bound(x => x.Language).Title("Language");
columns.Bound(x => x.Status).Title("Status");
}
)
.Pageable()
.Scrollable()
.Sortable()
.Selectable()
.ToolBar(
toolbar => toolbar.Create().Text("New") …Run Code Online (Sandbox Code Playgroud) 我必须使用Kendo DropDownLists,我想在第一个DDL的值被加载并且限制为我的viewmodel的值时禁用第二个DDL.
所以我有这样的代码:
@(Html.Kendo().DropDownList()
.Name("FormGroupId")
.HtmlAttributes(new { style = "width:250px" })
.OptionLabel("Select form group...")
.Template("#= data.Name # - #= data.Version #")
.DataTextField("Name")
.DataValueField("Id")
.Events(events =>
{
events.Change("onFormGroupChanged");
events.Select("onFormGroupSelected");
events.Cascade("onFormGroupCascaded");
})
.DataSource(source =>
{
source.Read(read => { read.Route(RouteConfig.GetFormGroupNames.Name); });
})
)
Run Code Online (Sandbox Code Playgroud)
和
@(Html.Kendo().DropDownList()
.Name("Schema")
.HtmlAttributes(new { style = "width:250px" })
.OptionLabel("Select schema...")
.DataTextField("SchemaName")
.DataValueField("SchemaId")
.DataSource(source =>
{
source.Read(read =>
{
read.Route(RouteConfig.FilterFormSchemas.Name).Data("filterSchemas");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("FormGroupId")
)
Run Code Online (Sandbox Code Playgroud)
我在第一个DDL上订阅了Cascade事件,并尝试从那里禁用第二个DDL,但它不起作用.
JS:
function onFormGroupCascaded(e) {
$("#Schema").data("kendoDropDownList").enable(false);
}
Run Code Online (Sandbox Code Playgroud) 在 Xamarin 项目中,我有带有以下代码的 PCL 库。
我们定义一个ConcurrentQueue<SyncRequest>. 对于哪个对象初始化,消费者Task已附加:
_syncConsumer = new Task(
ProcessSyncQueue,
_syncConsumerCancellationTokenSource.Token);
_syncConsumer.Start();
Run Code Online (Sandbox Code Playgroud)
该ProcessSyncQueue方法扫描同步队列并调用GetSyncableEntity方法:
private async void ProcessSyncQueue()
{
while (true)
{
SyncRequest syncRequest;
if (_syncQueue.TryDequeue(out syncRequest))
{
var syncableEntity = GetSyncableEntity(syncRequest);
}
}
}
Run Code Online (Sandbox Code Playgroud)
GetSyncableEntity 依次执行 Json 反序列化:
private T GetSyncableEntity(SyncRequest syncRequest)
{
T syncableEntity = default(T);
try
{
syncableEntity = JsonConvert.DeserializeObject<T>(syncRequest.SynchronizationContent);
}
catch (Exception e)
{
}
return syncableEntity;
}
Run Code Online (Sandbox Code Playgroud)
在此步骤中,我们收到ThreadAbortedException“线程正在中止”消息。堆栈跟踪:
at Newtonsoft.Json.JsonTextReader.FinishReadStringIntoBuffer(Int32 charPos, Int32 initialPosition, Int32 …Run Code Online (Sandbox Code Playgroud) c# ×9
asp.net-mvc ×2
c#-4.0 ×2
javascript ×2
kendo-ui ×2
task ×2
.net ×1
algorithm ×1
autofac ×1
azure ×1
binding ×1
clr ×1
comparison ×1
dynamic ×1
json ×1
json.net ×1
kendo-grid ×1
python ×1
telerik ×1
xamarin ×1