我是使用Unity的新手,但我的问题是每当我调用我的Web服务时,我都会得到一个例外情况
"确保控制器具有无参数的公共构造函数"
我已经遵循了多个教程,我仍然遇到同样的问题.
在我的WebApiConfig类的Register函数中,我有
var container = new UnityContainer();
container.RegisterType<IValidator, Validator>(new HierarchicalLifetimeManager());
config.DependencyResolver = new UnityResolver(container);
Run Code Online (Sandbox Code Playgroud)
这是我的UnityResolver类
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Web.Http.Dependencies;
public class UnityResolver : IDependencyResolver
{
protected IUnityContainer container;
public UnityResolver(IUnityContainer container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
this.container = container;
}
public object GetService(Type serviceType)
{
try
{
return container.Resolve(serviceType);
}
catch (ResolutionFailedException)
{
return null;
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
try
{
return container.ResolveAll(serviceType);
}
catch (ResolutionFailedException) …Run Code Online (Sandbox Code Playgroud) 好吧,我已经被困在这里一段时间了,我确信这是相对愚蠢的
http://plnkr.co/edit/YcBnbE5VCU5rizkDWreS?p=preview
<head>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js"></script>
<script >
function myCtrl($scope, $window) {
$scope.vm = {};
$scope.vm.Courses = [
{ Id: 1, Name: "Course 1"},
{ Id: 2, Name: "Course 2"}
];
$scope.OpenCourse = function(courseId) {
$window.alert("Called " + courseId);
}
}
</script>
</head>
<body ng-controller="myCtrl">
<div>
<div ng-repeat="course in vm.Courses" ng-click="vm.OpenCourse(course.Id)">
<div>
<div>
<label>{{course.Name}}</label>
</div>
</div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
为什么不在这里点击ng-click?这个问题似乎被问了很多,但没有一个答案似乎有所帮助.它看起来像重复移动div使它工作,但再次,我不知道为什么.
谢谢
我使用角2材质的DatePicker的组件在这里,我希望能够动态地设置(即YYYY-MM-DD或DD-MM-YYYY等)的显示格式
似乎有一种方法可以通过覆盖使用的"日期适配器"来全局扩展,但这对我不起作用,因为我可能需要不同的日期时间选择器来使用不同的格式.我不能全局设置它.这有什么已知的解决方法吗?
public void DeployCourse(Course course, Client client)
{
if (course == null) throw new ArgumentNullException("Course cannot be null");
if (client == null) throw new ArgumentNullException("Client cannot be null");
try
{
_ftp.Transfer(client.Server.IPAddress, course.PackageUrl, course.CourseName);
}
catch (Exception e)
{
var newException = new Exception(String.Format(
"Error deploying Course: {0} to Client: {1}. See inner exception for more details",
course.CourseName, client.Name), e);
throw newException;
}
}
Run Code Online (Sandbox Code Playgroud)
我从来没有真正理解构成"好"异常处理的内容.一个快速的谷歌搜索显示,几乎一致,人们同意在调用堆栈深处捕获和重新抛出异常是不好的.上面,我有一些我正在写的代码的例子.这在典型的调用堆栈中非常低.我之所以这样做,是因为如果没有这段代码,很难找到无法部署的课程.我的问题是,如果我在许多(如果不是全部)方法中做了类似的事情,为异常添加更多上下文,为什么这会被视为反模式?
谢谢!
接下来在我的Big O问题系列中,我找不到答案
以下面的例子为例
for(int i = 0; i < someNumber; i++)
{
for(int j = i; j < someNumber; j++)
{
DoSomething();
}
}
Run Code Online (Sandbox Code Playgroud)
这仍然被认为是O(n ^ 2)?我只是问,因为我认为这必须小于O(n ^ 2),因为内部循环对于i的每次迭代执行越来越少(因为j越来越接近someNumber).
谢谢
我不知道这是否可能(看起来不可能),但我试图找到一种方法来检测 HTML 输入标签的 onKeyDown 或 onKeyPress 事件中的结果值是什么。
我使用这些事件很重要。我不能只使用 onKeyUp,因为到那时输入已经改变了。我想首先防止它发生。我还尝试将按下的键字符附加到字符串的末尾,但这并没有考虑您在输入字段的字符串开头键入字符的情况。
有任何想法吗?我已经找了一段时间,似乎不可能,但我想我会问。
我一直在为一些采访做一些练习问题,我对某些事感到好奇.例如,在以下算法中说
foreach(User friend in friends)
{
foreach(Purchase purchase in friend.Purchases)
{
allFriendsPurchases.Add(purchase);
}
}
Run Code Online (Sandbox Code Playgroud)
所以,通过每个朋友是O(n),因为我们正在遍历所有的朋友.但是子循环怎么样?有些朋友可能没有购买任何东西,有些朋友已经购买了很多东西.您如何描述Big O Notation中的运行时间?
谢谢