那是我的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) 我已经阅读了很多关于站点文件夹结构(开发和部署)的文章和问题,但仍然对以下问题有误解。
我标记了我当前的文件夹结构:
有几个问题我想找到答案:
我会很高兴得到任何帮助,ty。
有方法签名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>或我必须自己进行转换?
我有一节课:
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)
但是,当我将模式更改为 …
我想记录我在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) 如果您的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所有具有重复项的行(如结果上部).
我想使用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) 有没有办法可以实现下一个行为?
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) .net ×5
c# ×4
asp.net-mvc ×3
asp.net ×2
angularjs ×1
asp.net-core ×1
bower ×1
dapper ×1
gruntjs ×1
gulp ×1
masstransit ×1
sql ×1
sql-server ×1
structuremap ×1
t-sql ×1