Search Results

Search found 8 results on 1 pages for 'perwebrequest'.

Page 1/1 | 1 

  • Windsor PerWebRequest resolution in Application_Start

    - by zaph0d
    I am injecting HttpContextBase into a caching class. HttpContextBase is registered as PerWebRequest. I interact with the caching class on each web request and this works fine, but I also need to initialise the cache at application start. I understand that PerWebRequest does not work in Application_Start though: http://stackoverflow.com/questions/2670717/castle-perrequestlifestyle-not-recognize What is the best way to resolve this in my situation?

    Read the article

  • PerWebRequest LifetimeManager and Beyond (Asp.net Mvc)

    - by Soe Moe
    Hi, Currently, I created my custom PerWebRequestLifetimeManager using HttpContext.Current.Items as backing store. I used that lifetime manager for Linq2Sql DataContext. Eveything is working fine until I need to use Cache for storing data (for 5 min). After 5 min, I need to retrieve data from DB and put it into the Cache. To do so, I need to use Linq2Sql DataContext for retrieving data. But during that time, HttpContext.Current is null because which was happened when cache is expired; not in Web Request. So, what kind of LifetimeManager should I use for this scenario? Thanks in advance.

    Read the article

  • castle PerRequestLifestyle not recognize

    - by Herman
    Hi all, New to Castle/Windsor, please bear with me. I am currently using the framework System.Web.Mvc.Extensibility and in its start up code, it registered HttpContextBase like the following: container.Register(Component.For<HttpContextBase>().LifeStyle.Transient.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current))); What I wanted to do is to change the behavior and change the lifestyle of httpContextBase to be PerWebRequest. so I have change the code to the following: container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current))); However, when I do this, I got the following error: System.Configuration.ConfigurationErrorsException: Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" />' to the <httpModules> section on your web.config which I did under <system.web> and <system.webServer>, however, I am still getting the same error. Any hints? Thanks in advance.

    Read the article

  • Linq to SQL DataContext Windsor IoC memory leak problem

    - by Mr. Flibble
    I have an ASP.NET MVC app that creates a Linq2SQL datacontext on a per-web-request basis using Castler Windsor IoC. For some reason that I do not fully understand, every time a new datacontext is created (on every web request) about 8k of memory is taken up and not released - which inevitably causes an OutOfMemory exception. If I force garbage collection the memory is released OK. My datacontext class is very simple: public class DataContextAccessor : IDataContextAccessor { private readonly DataContext dataContext; public DataContextAccessor(string connectionString) { dataContext = new DataContext(connectionString); } public DataContext DataContext { get { return dataContext; } } } The Windsor IoC webconfig to instantiate this looks like so: <component id="DataContextAccessor" service="DomainModel.Repositories.IDataContextAccessor, DomainModel" type="DomainModel.Repositories.DataContextAccessor, DomainModel" lifestyle="PerWebRequest"> <parameters> <connectionString> ... </connectionString> </parameters> </component> Does anyone know what the problem is, and how to fix it?

    Read the article

  • Castle Windsor upgrade causes TypeLoadException for generic types

    - by Neil Barnwell
    I have the following mapping in my Castle Windsor xml file which has worked okay (unchanged) for some time: <component id="defaultBasicRepository" service="MyApp.Models.Repositories.IBasicRepository`1, MyApp.Models" type="MyApp.Models.Repositories.Linq.BasicRepository`1, MyApp.Models" lifestyle="perWebRequest"/> I got this from the Windsor documentation at http://www.castleproject.org/container/documentation/v1rc3/usersguide/genericssupport.html. Since I upgraded Windsor, I now get the following exception at runtime: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.TypeLoadException: GenericArguments[0], 'T', on 'MyApp.Models.Repositories.Linq.BasicRepository`1[TEntity]' violates the constraint of type parameter 'TEntity'. Source Error: Line 44: public static void ConfigureIoC() Line 45: { Line 46: var windsor = new WindsorContainer("Windsor.xml"); Line 47: Line 48: ServiceLocator.SetLocatorProvider(() = new WindsorServiceLocator(windsor)); I'm using ASP.NET MVC 1.0, Visual Studio 2008 and Castle Windsor as downloaded from http://sourceforge.net/projects/castleproject/files/InversionOfControl/2.1/Castle-Windsor-2.1.1.zip/download Can anyone shed any light on this? I'm sure the upgrade of Castle Windsor is what caused it - it's been working well for ages.

    Read the article

  • How to register assemblies using Windsor in ASP.NET MVC

    - by oz
    This is how my project looks: TestMvc (my web project) has a reference to the DomainModel.Core assembly where my interfaces and business objects reside. The class that implements the interfaces in DomainModel.Core is in a different assembly called DomainModel.SqlRepository; the reason behind it is that if I just want to create a repository for Oracle I just have to deploy the new dll, change the web.config and be done with it. When I build the solution, if I look at the \bin folder of my TestMvc project, there is no reference to the DomainModel.SqlRepository, which makes sense because it's not being reference anywhere. Problem arises when my windsor controller factory tries to resolve that assembly, since it's not on the \bin directory. So is there a way to point windsor to a specific location, without adding a reference to that assembly? My web.config looks like this: <component id="UserService" service="TestMvc.DomainModel.Core.Interface, TestMvc.DomainModel.Core" type="TestMvc.DomainModel.SqlRepository.Class, TestMvc.DomainModel.SqlRepository" lifestyle="PerWebRequest" /> There's many ways around this, like copying the dll as part of the build, add the reference to the project so it will get copied to the \bin folder or install it on the GAC and add an assembly reference in the web.config. I guess my question is specific to Windsor, to see if I can give the location of my assembly and it will resolve it.

    Read the article

  • Castle Windsor, Fluent Nhibernate, and Automapping Isession closed problem

    - by SImon
    I'm new to the whole castle Windsor, Nhibernate, Fluent and Automapping stack so excuse my ignorance here. I didn't want to post another question on this as it seems there are already a huge number of questions that try to get a solution the Windsor nhib Isession management problem, but none of them have solved my problem so far. I am still getting a ISession is closed exception when I'm trying to call to the Db from my Repositories,Here is my container setup code. container.AddFacility<FactorySupportFacility>() .Register( Component.For<ISessionFactory>() .LifeStyle.Singleton .UsingFactoryMethod(() => Fluently.Configure() .Database( MsSqlConfiguration.MsSql2005. ConnectionString( c => c.Database("DbSchema").Server("Server").Username("UserName").Password("password"))) .Mappings ( m => m.AutoMappings.Add ( AutoMap.AssemblyOf<Message>(cfg) .Override<Client>(map => { map.HasManyToMany(x => x.SICCodes).Table("SICRefDataToClient"); }) .IgnoreBase<BaseEntity>() .Conventions.Add(DefaultCascade.SaveUpdate()) .Conventions.Add(new StringColumnLengthConvention(),new EnumConvention()) .Conventions.Add(new EnumConvention()) .Conventions.Add(DefaultLazy.Never()) ) ) .ExposeConfiguration(ConfigureValidator) .ExposeConfiguration(BuildDatabase) .BuildSessionFactory() as SessionFactoryImpl), Component.For<ISession>().LifeStyle.PerWebRequest.UsingFactoryMethod(kernel => kernel.Resolve<ISessionFactory>().OpenSession() )); In my repositories i inject private readonly ISession session; and use it as followes public User GetUser(int id) { User u; u = session.Get<User>(id); if (u != null && u.Id > 0) { NHibernateUtil.Initialize(u.UserDocuments); } return u; in my web.config inside <httpModules>. i have also added this line <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor"/> I'm i still missing part of the puzzle here, i can't believe that this is such a complex thing to configure for a basic need of any web application development with nHibernate and castle Windsor. I have been trying to follow the code here windsor-nhibernate-isession-mvc and i posted my question there as they seemed to have the exact same issue but mine is not resolved.

    Read the article

  • Problem Registering a Generic Repository with Windsor IoC

    - by Robin
    I’m fairly new to IoC and perhaps my understanding of generics and inheritance is not strong enough for what I’m trying to do. You might find this to be a mess. I have a generic Repository base class: public class Repository<TEntity> where TEntity : class, IEntity { private Table<TEntity> EntityTable; private string _connectionString; private string _userName; public string UserName { get { return _userName; } set { _userName = value; } } public Repository() {} public Repository(string connectionString) { _connectionString = connectionString; EntityTable = (new DataContext(connectionString)).GetTable<TEntity>(); } public Repository(string connectionString, string userName) { _connectionString = connectionString; _userName = userName; EntityTable = (new DataContext(connectionString)).GetTable<TEntity>(); } // Data access methods ... ... } and a SqlClientRepository that inherits Repository: public class SqlClientRepository : Repository<Client> { private Table<Client> ClientTable; private string _connectionString; private string _userName; public SqlClientRepository() {} public SqlClientRepository(string connectionString) : base(connectionString) { _connectionString = connectionString; ClientTable = (new DataContext(connectionString)).GetTable<Client>(); } public SqlClientRepository(string connectionString, string userName) : base(connectionString, userName) { _connectionString = connectionString; _userName = userName; ClientTable = (new DataContext(connectionString)).GetTable<Client>(); } // data access methods unique to Client repository ... } The Repository class provides some generics methods like Save, Delete, etc, that I want all my repository derived classes to share. The TEntity parameter is constrained to the IEntity interface: public interface IEntity { int Id { get; set; } NameValueCollection GetSaveRuleViolations(); NameValueCollection GetDeleteRuleViolations(); } This allows the Repository class to reference these methods within its Save and Delete methods. Unit tests work fine on mock SqlClientRepository instances as well as live unit tests on the real database. However, in the MVC context: public class ClientController : Controller { private SqlClientRepository _clientRepository; public ClientController(SqlClientRepository clientRepository) { this._clientRepository = clientRepository; } public ClientController() { } // ViewResult methods ... ... } ... _clientRepository is always null. I’m using Windor Castle as an IoC container. Here is the configuration: <component id="ClientRepository" service="DomainModel.Concrete.Repository`1[[DomainModel.Entities.Client, DomainModel]], DomainModel" type="DomainModel.Concrete.SqlClientRepository, DomainModel" lifestyle="PerWebRequest"> <parameters> <connectionString>#{myConnStr}</connectionString> </parameters> </component> I’ve tried many variations in the Windsor configuration file. I suspect it’s more of a design flaw in the above code. As I'm looking over my code, it occurs to me that when registering components with an IoC container, perhaps service must always be an interface. Could this be it? Does anybody have a suggestion? Thanks in advance.

    Read the article

1