我已经开始在本教程之后使用Autofac:http://flexamusements.blogspot.com/2010/09/dependency-injection-part-3-making-our.html
构造函数中没有参数的简单类
builder.RegisterType<ConsoleOutputService>().As<IOutputService>();
Run Code Online (Sandbox Code Playgroud)
如教程中所述,上面的代码可以理解为:setup ConsoleOutputService作为IOutputService的实现
在构造函数中有一个参数的简单类
builder.Register(c => new MultipleOutputService(outputFilePath)).As<IOutputService>();
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我们使用lambda表达式来注册这个类(以及这个表达式到底做了什么)以及为什么我们不能输入这个代码
builder.RegisterType<MultipleOutputService(outputFilePath)>().As<IOutputService>();
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助
我开始学习打字稿和Vuejs.
任何人都可以解释我为什么我不能从计算的allChecked()访问数据中的帐户属性?
import * as Vue from "vue";
declare var accounts: any[];
var app = new Vue({
el: '#vueowner',
data: {
accounts: accounts,
hasAccount: this.accounts.length > 0,
checkedAccounts: []
},
computed: {
allChecked() {
return this.accounts.length === this.checkedAccounts.length;
}
}
})
Run Code Online (Sandbox Code Playgroud)
我有这个错误
ERROR in index.ts
(25,25): error TS2339: Property 'accounts' does not exist on type 'Vue'.
ERROR in index.ts
(25,50): error TS2339: Property 'checkedAccounts' does not exist on type 'Vue'.
Run Code Online (Sandbox Code Playgroud) Pulumi 有没有办法访问当前堆栈名称,以便在执行 pulumi up 时选择运行哪个类?
我想做这样的事情:
static Task<int> Main()
{
if (Deployment.Instance.StackName.StartsWith("local-"))
return Deployment.RunAsync<LocalStack>();
return Deployment.RunAsync<AzureStack>();
}
Run Code Online (Sandbox Code Playgroud) 我用ASP.NET vnext创建了一个非常小的项目,它带有一个简单的MVC控制器和一个简单的Api控制器.
在localhost上,一切正常.如果我部署到azure网站,只有MVC部分正在运行
这是我的project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"exclude": [
"wwwroot"
],
"packExclude": [
"node_modules",
"bower_components",
"**.kproj",
"**.user",
"**.vspscc"
],
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
"Microsoft.AspNet.Mvc": "6.0.0-beta2"
},
"frameworks" : {
"aspnet50" : { },
"aspnetcore50" : { }
}
}
Run Code Online (Sandbox Code Playgroud)
Startup.cs
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
namespace Project.Web6
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
app.UseMvc();
}
} …Run Code Online (Sandbox Code Playgroud) 我已经开发了一个简单的IIdentity和IPrincipal我的MVC项目,我想覆盖User和User.Identity以正确的类型返回值
这是我的自定义身份:
public class MyIdentity : IIdentity
{
public MyIdentity(string name, string authenticationType, bool isAuthenticated, Guid userId)
{
Name = name;
AuthenticationType = authenticationType;
IsAuthenticated = isAuthenticated;
UserId = userId;
}
#region IIdentity
public string Name { get; private set; }
public string AuthenticationType { get; private set; }
public bool IsAuthenticated { get; private set; }
#endregion
public Guid UserId { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的自定义校长:
public class MyPrincipal : …Run Code Online (Sandbox Code Playgroud) 我目前正在使用OWIN将WebApi 1移动到WebApi 2项目.
在这段代码中,GlobalConfiguration位于System.Web.Http.WebHost中.
public class HandlerErrorFilterAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext context)
{
var logFactory = GlobalConfiguration.Configuration.DependencyResolver
.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
...
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这不是Owin兼容,但我找不到如何重写这个,所以我可以访问依赖解析器.
谁能解释为什么这段代码不起作用:
async Task Main()
{
using (var smtpClient = new SmtpClient(@"127.0.0.1", 25))
{
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
var from = new MailAddress(@"sender@mydomain.com");
var to = new MailAddress(@"receiver@mydomain.com");
using (var message = new MailMessage())
{
message.Subject = "Email Subject";
message.Body = "<html><head></head><body><h1>Hello World!</h1></body></html>";
message.IsBodyHtml = true;
message.From = from;
message.To.Add(to);
message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString("Hello World!", null, MediaTypeNames.Text.Plain));
await smtpClient.SendMailAsync(message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出消息是:
MIME 版本:1.0 发件人:sender@mydomain.com 收件人:receiver@mydomain.com 日期:2016 年 5 月 12 日 14:51:30 +0200 主题:电子邮件主题内容类型:multipart/alternative;边界=--boundary_2_be88a42a-4d48-4096-b4e0-71fb7857809f
----boundary_2_be88a42a-4d48-4096-b4e0-71fb7857809f 内容类型:文本/普通;charset=us-ascii 内容传输编码:引用打印
你好,世界!
----boundary_2_be88a42a-4d48-4096-b4e0-71fb7857809f 内容类型:文本/普通;charset=us-ascii 内容传输编码:引用打印你好,世界!----boundary_2_be88a42a-4d48-4096-b4e0-71fb7857809f--
此代码正在工作: …
我正在创建一个将与多个堆栈共享的 ACR,我需要输出中的信息
如何保护密码输出?
using Pulumi;
using Pulumi.Azure.Core;
using Pulumi.Azure.ContainerService;
class MyStack : Stack
{
public MyStack()
{
string baseName = $"{Deployment.Instance.ProjectName}-{Deployment.Instance.StackName}";
string restrictedName = baseName.ToLower().Replace("-", "");
var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
{
Name = baseName
});
var acr = new Registry("myorg-acr", new RegistryArgs
{
Name = $"{restrictedName}acr",
ResourceGroupName = resourceGroup.Name,
Sku = "Basic",
AdminEnabled = true
});
AcrLoginServer = acr.LoginServer;
AcrAdminUsername = acr.AdminUsername;
AcrAdminPassword = acr.AdminPassword;
}
[Output]
public Output<string> AcrLoginServer { get; private set; }
[Output]
public …Run Code Online (Sandbox Code Playgroud) 我用MongoDb C#Driver 1.4更新了我的项目,我的一个Lambda表达式不再工作了.
在我使用MongoDb C#Driver 1.3.1与Fluent Mongo支持Linq之前.
这是我的方法:
IQueryable<T> IBackend<T>.Get(System.Linq.Expressions.Expression<Func<T, bool>> expression)
{
return collection.AsQueryable<T>().Where(expression);
}
Run Code Online (Sandbox Code Playgroud)
这个lambda表达式有效:
var addedCustomer = repo.Get(c => c.FirstName == "Elwood").SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)
这个现在引发了一个例外:
var updatedCustomer = repo.Get(c => c.Id == customer.Id).SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)
抛出的异常消息:
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
这里更新是我的堆栈跟踪:
MongoDB.Bson.dll!MongoDB.Bson.Serialization.BsonClassMapSerializer.GetMemberSerializationInfo(string memberName) Line 253 + 0x3 bytes C#
MongoDB.Driver.dll!MongoDB.Driver.Linq.SelectQuery.GetSerializationInfoMember(MongoDB.Bson.Serialization.IBsonSerializer serializer, System.Linq.Expressions.MemberExpression memberExpression) Line 962 + 0xc bytes C#
MongoDB.Driver.dll!MongoDB.Driver.Linq.SelectQuery.GetSerializationInfo(MongoDB.Bson.Serialization.IBsonSerializer serializer, System.Linq.Expressions.Expression expression) Line 888 + 0xf bytes C#
MongoDB.Driver.dll!MongoDB.Driver.Linq.SelectQuery.GetSerializationInfo(System.Linq.Expressions.Expression expression) Line 880 + 0xf …Run Code Online (Sandbox Code Playgroud) 如何使用vuejs 2动态连接文本
这就是我现在拥有的:
<span class="label" :class="label-{{account.Segment}}">{{account.Segment}}</span>
Run Code Online (Sandbox Code Playgroud)
account.Segment =="ABC"
我需要渲染的是
<span class="label label-ABC">ABC</span>
Run Code Online (Sandbox Code Playgroud) c# ×4
pulumi ×2
vuejs2 ×2
asp.net-core ×1
asp.net-mvc ×1
autofac ×1
azure ×1
c#-4.0 ×1
iidentity ×1
katana ×1
mailmessage ×1
mongodb ×1
owin ×1
typescript ×1