小编Nei*_*sey的帖子

RabbitMQ与.NET中的Unity IOC容器

我使用Unity App Block作为我的WOC项目服务层的IOC容器.使用Unity.WCF库将其插入每个WCF服务时,这非常有效.

我最近将RabbitMQ引入了我的服务层,我目前正在使用"使用"块来连接并添加到队列中.我不喜欢这个,我想用它HierachicalLifetimeManager来创建和销毁我与RabbitMQ的连接,因为我需要它们?这听起来不错吗?

我正在寻找一个这样的样本,或者至少是关于最佳方法的一些指导?(例如,我是否应该封装连接并根据需要注入每个服务?我将如何封装RabbitMQ使用者等?)

.net unity-container rabbitmq

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

单点登录,有2个子域,一个Java,一个.NET

我目前正在为上述问题寻找一个很好的解决方案.我们可能会在.NET上运行表单身份验证.

我运行了一个ASP.NET MVC应用程序,a.mydomain.com并运行了一个基于Java的应用程序b.mydomain.com.

什么是最好的方法,这样我就不必登录每个应用程序.比如,当我登录a.mydomain.com然后打开Java时b.mydomain.com,它会检查并看到我已经登录了?

WCF AuthenticationService类是否适用于此?我可以从JavaScript中做一个AJAX请求b.mydomain.com来检查我是否已经在.NET应用程序中登录了吗?

c# asp.net-mvc forms-authentication

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

工作单元,实体框架DBContext范围

我遇到了一个问题,EF寻找这个问题的最佳实践:

public void TestEntityFramework_UOWImplementation()
{
    using (UnitOfWorkInventory uow = new UnitOfWorkInventory())
    {
        IMaterialRepository repos = new MaterialRepository(uow);

        Material mat = GetMaterial("Mikes Material", 1);

        mat.CostPrice = 20;

        repos.InsertOrUpdate(mat);

        uow.Commit();
    }
}

private Material GetMaterial(string sku, int clientId)
{
    IMaterialRepository repos = new MaterialRepository(new UnitOfWorkInventory();

    return repos.Find(sku, clientId);

}
Run Code Online (Sandbox Code Playgroud)

在TestEntityFramework_UOWImplementation()方法中,它很好,我调用为我的工作单元创建一个范围..并在其中创建一个存储库.

但是,当我想getMaterials()如下所示..我无法访问工作单元或存储库,除非我实际将其作为参数传递!这显然不是特别好.

人们如何解决这个问题?

提前致谢!

尼尔

entity-framework unit-of-work repository-pattern

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

违反PRIMARY KEY约束'PK_dbo.AmazonProducts'.无法在对象中插入重复键

我在尝试保存作为父对象的外键的实体时遇到问题.

我有一个amazonProduct实体.还有一个AmazonCompetitivePrice实体,它是amazonProduct上的虚拟列表,如下所示:

public class AmazonProduct
{
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public virtual int ASIN

        public virtual IList<AmazonProductCompetitivePrice> amazonProductCompetitivePrices = new List<AmazonProductCompetitivePrice>();
}
Run Code Online (Sandbox Code Playgroud)

所以我有一个AmazonProduct,我从数据库中检索,然后将新的AmazonProductCompetitivePrice添加到amazonProduct.

但是当我尝试保存时,我收到以下错误:

违反PRIMARY KEY约束'PK_dbo.AmazonProducts'.无法在对象'dbo.AmazonProducts'中插入重复键.\ r \n语句已终止

看起来它没有意识到我的AmazonProduct已经在数据库中了,并且它试图保存一个新的,但主键已经存在!

我使用流畅的API来映射外键,如下所示:

        modelBuilder.Entity<AmazonProduct>()
                    .HasMany(pl => pl.AmazonProductCompetitivePrices)
                    .WithOptional(p => p.AmazonProduct)
                    .Map(c => c.MapKey("ASIN"));
Run Code Online (Sandbox Code Playgroud)

有人知道这有什么不对吗?

提前致谢!

编辑: 对象检索:

 using (var uow = new UnitOfWorkInventory())
            {
                using (var amazRepo = new AmazonProductRepository(uow))
                {
                    return amazRepo.FindByAsin(ASIN);
                }
            }
 public AmazonProduct FindByAsin(string asin)
        {
            return context.AmazonProducts.Include(x => x.AmazonLowestOfferListings).Include(x => x.AmazonMyPrices).Include(x => x.AmazonProductCompetitivePrices).SingleOrDefault(x => x.ASIN == asin);
        }
Run Code Online (Sandbox Code Playgroud)

这让我获得了AmazonProduct ..然后保存: …

c# entity-framework

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