小编FSo*_*ou1的帖子

尝试获取AccountController类型的实例时发生激活错误,键\"\""

那是我的AccountController:

[Authorize]
public class AccountController : Controller
{
    private UserManager<User> _userManager { get; set; }

    public AccountController() : this(new UserManager<User>(new UserStore())) {}

    public AccountController(UserManager<User> userManager) {
        _userManager = userManager;
    }
}
Run Code Online (Sandbox Code Playgroud)

和堆栈跟踪:

Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code
  HResult=-2146233088
  Message=Activation error occurred while trying to get instance of type AccountController, key ""
  Source=Microsoft.Practices.ServiceLocation
  StackTrace:
       at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53
       at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType) in c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 34
       at System.Web.Mvc.DependencyResolver.DelegateBasedDependencyResolver.GetService(Type type)
  InnerException: StructureMap.StructureMapException
       HResult=-2146232832
       Message=StructureMap Exception Code:  202 …
Run Code Online (Sandbox Code Playgroud)

.net structuremap asp.net asp.net-mvc

6
推荐指数
2
解决办法
2万
查看次数

ASP.NET MVC、AngularJS、Bower 和部署站点文件夹结构

我已经阅读了很多关于站点文件夹结构(开发和部署)的文章和问题,但仍然对以下问题有误解。

我标记了我当前的文件夹结构:

  • Orange- 看起来像libvendor文件夹,我想在其中存储独立组件;
  • Blue- 文件夹包含我自己的,相对于当前项目(应用程序)文件;
  • Green-ready to deploy 文件夹,其中包含缩小和合并的文件,这些文件曾经包含在 index.html 中。

有几个问题我想找到答案:

  • 是否正确,最佳实践是仅部署到 Web 服务器的dist文件夹?
  • 我应该将我的bower_componentsapp javascript 文件合并到单个 app.min.js 文件中吗?我应该将独立组件与应用程序文件和 ober 排序混淆吗?
  • 我应该将带有模板的视图文件夹按原样部署到dist/views文件夹中吗?
  • 将所有图像(css 图像、应用程序图像、插件图像)混入单个dist/images文件夹是否正确?
  • 视图文件夹中存储指令模板是否正确?
  • 没有相对于 AngularJS client/app/js/common/helpers.js文件,-我不知道哪里是最明显的地方(它可能是原型、自定义函数或对象)

我会很高兴得到任何帮助,ty。

在此处输入图片说明

asp.net-mvc angularjs gruntjs bower gulp

5
推荐指数
1
解决办法
4306
查看次数

IEnumerable到IList之间的转换(Dapper返回结果)

有方法签名UserManager(ASP .NET Identity Core默认实现):

public Task<IList<string>> GetRolesAsync(User user) {
    const string query = @"
                select r.[Name]
                  from [UserRoles] ur
             left join [Roles] r on r.RoleId = ur.RoleId
                 where ur.UserId = @userId;
    ";

    return Task.Factory.StartNew(() => {
        using (SqlConnection connection = new SqlConnection(_connectionString))
            return connection.Query<string>(query, new { userId = user.UserId });
    });
}
Run Code Online (Sandbox Code Playgroud)

但不幸的是Dapper.Query<T>返回IEnumerable<T>.

是否有可能返回IList<T>或我必须自己进行转换?

.net c# asp.net-mvc dapper

4
推荐指数
2
解决办法
3978
查看次数

垃圾收集器,调用和callvirt以及调试/释放代码模式执行差异

我有一节课:

public class SomeClass {
    public int I;

    public SomeClass(int input) {
        I = input;
        Console.WriteLine("I = {0}", I);
    }

    ~SomeClass() {
        Console.WriteLine("deleted");
    }

    public void Foo() {
        Thread.Sleep(1000);
        Console.WriteLine("Foo");
    }
}
Run Code Online (Sandbox Code Playgroud)

这个程序:

class Program {
    static void Main(string[] args) {
        new Thread(() => {
                       Thread.Sleep(100);
                       GC.Collect();
                   }) { IsBackground = true }.Start();

        new SomeClass(10).Foo();

        // The same as upper code
        // var t = new SomeClass(10);
        // t.Foo();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在调试模式下运行此代码时,我有下一个结果:

I = 10
Foo
deleted
Run Code Online (Sandbox Code Playgroud)

但是,当我将模式更改为 …

.net c# garbage-collection memory-management

2
推荐指数
1
解决办法
317
查看次数

MassTransit:有没有办法记录收入信息

我想记录我在MassTransit中消费的每条消息.有没有办法实现全局拦截器,我可以处理收入消息或使用配置实现它?

我当前的配置如下所示:

BusFactory = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
    var host = cfg.Host(new Uri(AppSettings.RmqConnectionString), h => { });

    cfg.UseNLog();

    cfg.ReceiveEndpoint(host, RmqPropertyKeys.CallbackQueue, e=> e.LoadFrom(container));
});
Run Code Online (Sandbox Code Playgroud)

.net masstransit

2
推荐指数
1
解决办法
1038
查看次数

如果只有一列具有值,请删除重复项

如果您的Id列和Value列具有重复行,则这很容易.但在采访中我被问到如何删除它,如果你只有Value列.例如:

table_a输入:

Value
A
A
B
A
C
D
D
E
F
F
E
Run Code Online (Sandbox Code Playgroud)

table_a输出:

Value
A
B
C
D
E
F
Run Code Online (Sandbox Code Playgroud)

问题:您的表只有一列Value,您必须拥有delete所有具有重复项的行(如结果上部).

sql t-sql sql-server

1
推荐指数
2
解决办法
6275
查看次数

string.GetHashCode和IEqualityComparer &lt;string&gt; .Default.GetHashCode之间的区别

我想使用Distinct()声明为的数据IEnumerable<KeyValuePair<IdentType, string>>。在这种情况下,我必须自己实现IEqualityComparer,这里是我的问题:

以下实现之间有什么区别吗?

public int GetHashCode(KeyValuePair<IdentType, string> obj) {
    return EqualityComparer<string>.Default.GetHashCode(obj.Value);
}
Run Code Online (Sandbox Code Playgroud)

public int GetHashCode(KeyValuePair<IdentType, string> obj) {
    return obj.Value.GetHashCode();
}
Run Code Online (Sandbox Code Playgroud)

.net c#

1
推荐指数
1
解决办法
490
查看次数

HttpContextAccessor、IPrincipal 和 ServiceCollection

有没有办法可以实现下一个行为?

public static void Configure(IServiceCollection services) {
    services.AddScoped(typeof(Func<IPrincipal>), ???);
    services.AddInstance(typeof(Func<IPrincipal>), ???);
}
Run Code Online (Sandbox Code Playgroud)

1. 不工作:

Func<IServiceProvider, IPrincipal> getPrincipal = 
    (sp) => sp.GetService<IHttpContextAccessor>().HttpContext.User;

services.AddScoped(
    typeof(Func<IPrincipal>), 
    getPrincipal);  
Run Code Online (Sandbox Code Playgroud)

2. 不起作用:

var builder = services.BuildServiceProvider();

services.AddInstance(
    typeof(Func<IPrincipal>),
    builder.GetService<IHttpContextAccessor>().HttpContext.User);
Run Code Online (Sandbox Code Playgroud)

c# asp.net dependency-injection asp.net-core

1
推荐指数
1
解决办法
1609
查看次数