Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, may someone help me. I am building an ASP.NET MVC App. But I decide to use DDD pattern. As DI Container I am using Castle Winsor. But When I run the test using NUnit test, I have the following error
/* Test.RepositoriesTest.PostRepositoryTest.Get_All_Posts:
SetUp : Castle.MicroKernel.ComponentResolutionException : Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule
To fix this add
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
to the <httpModules> section on your web.config.
If you plan running on IIS in Integrated Pipeline mode, you also need to add the module to the <modules> section under <system.webServer>.
Alternatively make sure you have Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file.*/

My UnitOfWork is generic and live in the Infrastructure assembly:
C#
public class UnitOfWork<T> : IUnitOfWork<T> where T : class

and register in this way:
C#
container.Register(Component.For(typeof(IUnitOfWork<>)).ImplementedBy(typeof(UnitOfWork<>)));

And my Repository is also generic and live in Repository assembly:
C#
public abstract class Repository<T> : IRepository<T>, IUnitOfWorkRepository<T> where T : class
and register in this way:
container.Register(Classes.FromThisAssembly().BasedOn(typeof(IRepository<>)).WithService.FromInterface().LifestylePerWebRequest());

also I have from the same assembly (Repository):
C#
public class PostRepository:Repository<Post>,IPostRepository
    {
        #region Fields

        private readonly MiaffDBContext _context;
        private IUnitOfWork<Post> _uow;

        #endregion

        #region Constructors

        public PostRepository(MiaffDBContext context, IUnitOfWork<Post> unitOfWork) : base(context, unitOfWork)
        {
            _context = context;
            _uow = unitOfWork;
        }
        #endregion

And from Model assembly:
C#
public interface IPostRepository:IRepository<Post>

At this point, Why the Web.config file is needed in the Test assembly in order to test my DataAccess????

[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 17-Jan-12 2:17am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900