小编Use*_*ser的帖子

如何根据构造函数参数名称注入适当的依赖项

我有这个接口被少数具体类型使用,例如EmailFormatter,TextMessageFormatter等等.

public interface IFormatter<T>
{
    T Format(CompletedItem completedItem);
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题EmailNotificationService是,我想要注入EmailFormatter.此服务的构造函数签名是public EmailNotificationService(IFormatter<string> emailFormatter).

我很确定我之前已经看过这个,但我如何在Windsor中注册它,以便EmailFormatter在构造函数参数名称为emailFormatter?时注入?

这是我的温莎注册码.

container.Register(Component.For<IFormatter<string>>().ImplementedBy<EmailFormatter>());
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection castle-windsor

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

处理多用户环境

这是我第一次开发一个应用程序,将由10-15人使用,因为我不确定最小化更新冲突的好方法.

基本上,我的应用程序如下工作.新项目在收到后通过外部服务插入数据库.业务规则表明每个项目将由两名独立员工进行审核.不用说,项目和评论之间存在一对多的关系.什么是应用的一个重要方面是,没有项目可以超过2条评论中,系统必须跟踪谁是两个审稿人.此外,谁是第一个评论员,第二个.

现在,我有一切工作.我正在处理的问题是这个(许多类似场景之一).如果所有用户在相同的5分钟内刷新他们的项目列表会发生什么.用户1提交项目ID 1的评论.第二个人对同一项目提交评论.现在,第三人提交了对项目ID 1的评论,但已经有2条评论,因此该项目已被标记为已完成.

处理多用户环境的可能方法是什么,多个用户可能更新同一记录?

.net c# nhibernate multi-user

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

无实现类型的工厂问题

举个简单的例子:

class Program
{
    static void Main(string[] args)
    {
        var windsorContainer = new WindsorContainer();
        windsorContainer.Install(new WindsorInstaller());

        var editor = windsorContainer.Resolve<IEditor>();
        editor.DoSomething();

        Console.ReadKey();
    }
}

public class WindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.AddFacility<TypedFactoryFacility>();

        container.Register(Component.For<ISomeOtherDependency>().ImplementedBy<SomeOtherDependency>());
        container.Register(Component.For<IReviewingService>().ImplementedBy<ReviewingService>());
        container.Register(Component.For<IEditor>().ImplementedBy<Editor>());
        container.Register(Component.For<Func<IReviewingServiceFactory>>().AsFactory());
    }
}

public interface IEditor
{
    void DoSomething();
}

public class Editor : IEditor
{
    private readonly Func<IReviewingServiceFactory> _reviewingService;

    public Editor(Func<IReviewingServiceFactory> reviewingService)
    {
        _reviewingService = reviewingService;
    }

    public void DoSomething()
    {
        var rs = _reviewingService();
        var reviews = …
Run Code Online (Sandbox Code Playgroud)

dependency-injection castle-windsor

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