小编min*_*son的帖子

RazorEngine布局

我正在使用Razor引擎https://github.com/Antaris/RazorEngine来解析我的电子邮件模板的正文.是否可以定义布局并包含其他.cshtml文件?例如,公共页眉和页脚.

c# razorengine

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

WCF服务和业务逻辑

我不确定在哪里放置我的业务逻辑.我有一个WCF服务,它的方法暴露给我的客户端.

我的业务逻辑应该采用服务方法吗?

public User GetUser(int id)
{  
     //Retrieve the user from a repository and perform business logic
     return user;
}
Run Code Online (Sandbox Code Playgroud)

或者它应该在一个单独的类中,每个WCF服务方法将依次调用业务层方法.

public User GetUser(int id)
{  
     return _userLogic.GetUser(id);
}
Run Code Online (Sandbox Code Playgroud)

wcf business-logic-layer business-logic

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

RazorEngine内存使用情况

我创建了一个Windows服务来构建和发送电子邮件.我正在使用Razor Engine来解析电子邮件模板.我正在使用动态ExpandoObject来创建模型.

我的问题是当每个电子邮件被创建并发送时,内存正在增加,但它从未被发布.我已经使用Ants Memory Profiler(我以前没有使用过这个)来描述该服务,但它显示了以下结果:

使用Razor Engine

使用Razor.Parse(文本,模型)解析200封电子邮件

第1代:12.9kb

第2代:15.88mb

大型物体堆:290.9kb

分配给.NET的未使用内存:3.375mb

不受管理:69.51mb

内存碎片总数:197

没有剃刀引擎

返回200封未解析文本的电子邮件.

第1代:13.87kb

第2代:3.798mb

大型物体堆:95.58kb

分配给.NET的未使用内存:4.583mb

不受管理:44.58mb

内存碎片总数:7

使用Razor,最大的第2代实例是:

System.Reflection.Emit __FixUpData [] - 2,447,640个实时字节,3,138个实例

有谁知道为什么对象没有被释放而第二代正在增长?有没有办法在每次要解析模板时都有一个新的RazorEngine实例,当它完成时它将不会被引用并将转到GC.

我每次解析模板时都试过创建一个新的Template服务实例,但这并没有什么不同

using (ITemplateService templateService = new TemplateService())
{
     result = templateService.Parse<ExpandoObject>(text, model);
}
Run Code Online (Sandbox Code Playgroud)

razorengine

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

Autofac垃圾回收-BeginLifetimeScope

我创建了一个Windows服务来构建和发送电子邮件。我已经实现了依赖注入,并且将Autofac用作DI容器。

我的问题是,随着服务运行,分配的内存不断增长,目前超过1GB。我阅读了有关生存期的文章, 并从中合并了BeginLifetimeScope,而不是直接从容器中解决。但这并没有解决问题。任何建议表示赞赏。

以下是我的服务onStart方法中的Autofac配置。

ContainerBuilder builder = new ContainerBuilder();

//Register the Database context
builder.RegisterType<DbContainer>().As<IDbContainer>();

//Register a single shared instance of Email Manager which will be shared by all EmailProcessing instances
builder.Register(c => new EmailManager()).As<IEmailManager>()).SingleInstance();

//Register email processing classes
builder.Register(c => new EmailBuilder(c.Resolve<IDbContainer>(), c.Resolve<IEmailManager>())).As<IEmailBuilder>();

_container = builder.Build();
Run Code Online (Sandbox Code Playgroud)

下面是每5秒运行一次的电子邮件计时器方法。

private void EmailTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
     using (var lifetime = _container.BeginLifetimeScope())
     {
          //Builder, and any of its disposable dependencies, will
          //be disposed of when the using block completes
          IEmailBuilder builder = …
Run Code Online (Sandbox Code Playgroud)

autofac

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

将对象注入自定义WCF UserNamePassValidator - Autofac

我有一个托管在IIS中的服务.它由Web.config配置.

我创建了一个自定义的UserNamePassValidator,如果II在validate方法中有逻辑,它就可以工作.但我想在另一个项目中使用逻辑并使用DI注入如下.

public class UserNamePassValidator : System.IdentityModel.Selectors.UserNamePasswordValidator
{
    private readonly ISystemAuthentication _systemAuthentication;

    public UserNamePassValidator(ISystemAuthentication systemAuthentication)
    {
        _systemAuthentication = systemAuthentication;
    }

    public override void Validate(string userName, string password)
    {
        _systemAuthentication.Validate(userName, password))
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Autofac WCF集成.

var builder = new ContainerBuilder();
builder.RegisterType<AuthenticationService>().As<IAuthenticationService>();
builder.Register(c => new SystemAuthentication()).As<ISystemAuthentication>();
builder.Register(c => new UserNamePassValidator(c.Resolve<ISystemAuthentication>()));
AutofacHostFactory.Container = builder.Build();
Run Code Online (Sandbox Code Playgroud)

当我浏览到该服务时,我收到以下错误:

[MissingMethodException: No parameterless constructor defined for this object.]
Run Code Online (Sandbox Code Playgroud)

web.config行为;

 <userNameAuthentication
                 userNamePasswordValidationMode="Custom"
                 customUserNamePasswordValidatorType="MyNamespace.UserNamePassValidator, service" />
Run Code Online (Sandbox Code Playgroud)

我已阅读以下相关帖子,但示例是自托管服务: 如何将对象注入WCF验证器类

编辑

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="Namespace.AuthenticationServiceBehaviour" name="Namespace.AuthenticationService" >
        <endpoint address="" binding="wsHttpBinding" contract="Namespace.IAuthenticationService" bindingConfiguration="SafeServiceConf"> …
Run Code Online (Sandbox Code Playgroud)

wcf dependency-injection autofac wcf-security

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

Knockout JS"uniqueName"绑定 - 两个字段的名称相同

我正在使用Knockout JS创建一个编辑器.我使用foreach属性循环我的模型中的列表.

 <tbody data-bind='foreach: Properties'>
Run Code Online (Sandbox Code Playgroud)

我正在使用JQuery不显眼的验证,需要一个名称属性来验证.我想为两个字段分配相同的名称,以便能够输出验证消息.是否可以在两个字段上使用相同的uniqueName属性?

 <tr>
     <td>
         <input data-bind='value: type, uniqueName: true' data-val = "true", data-val-required = "The Type field is required"  /></td>
     </td>
 </tr>
 <tr>
     <td class="field-validation-valid" data-valmsg-for="UNIQUENAME" data-valmsg-replace="true"></td>
 </tr>
Run Code Online (Sandbox Code Playgroud)

我复制了下面的示例,其中显示了网格编辑和JQuery不显眼的验证.但我无法弄清楚如何将验证消息与输入字段链接

http://knockoutjs.com/examples/gridEditor.html

编辑:

我使用带有Razor语法的ASP.NET MVC3进行循环输入.

 @Html.DropDownList("Type", new SelectList(types, "Value", "Text"), "Select", new { data_bind = "value: Type", data_val = "true", data_val_required = "The Type field is required" })
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何更新名称属性.当我使用knokcout添加属性时,它们都具有相同的名称" 类型 ",并且验证不起作用.他们需要索引Type1 Type2等.

knockout.js

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