Search Results

Search found 200 results on 8 pages for 'windsor'.

Page 3/8 | < Previous Page | 1 2 3 4 5 6 7 8  | Next Page >

  • Windsor + NHibernate + ISession + MVC

    - by dbones
    Hi I am trying to get Windsor to give me an instance ISession for each request, which should be injected into all the repositories Here is my container setup container.AddFacility<FactorySupportFacility>().Register( Component.For<ISessionFactory>().Instance(NHibernateHelper.GetSessionFactory()).LifeStyle.Singleton, Component.For<ISession>().LifeStyle.Transient .UsingFactoryMethod(kernel => kernel.Resolve<ISessionFactory>().OpenSession()) ); //add to the container container.Register( Component.For<IActionInvoker>().ImplementedBy<WindsorActionInvoker>(), Component.For(typeof(IRepository<>)).ImplementedBy(typeof(NHibernateRepository<>)) ); Its based upon a StructureMap post here http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/ however, when this is run, a new Session is created for every object it is injected too. what am I missing? thanks in advanced (FYI the NHibernateHelper, sets up the config for Nhib)

    Read the article

  • Winforms MVP with Castle Windsor - DI for subforms?

    - by Paul Kirby
    I'm building a winforms app utilizing passive-view MVP and Castle Windsor as an IoC container. I'm still a little new to dependency injection and MVP, so I'm looking for some clarity... I have a main form which contains a number of user controls, and also will bring up other dialogs (ex. Login, options, etc) as needed. My first question is...should I use constructor injection to get the presenters for these other views into the main view, or should I go back to a Service Locator-type pattern? (which I've been told is a big nono!) Or something else? Second question...the user controls need to communicate back to the main form when they are "completed" (definition of that state varies based on the control). Is there a standard way of hooking these up? I was thinking perhaps just wiring up events between the main presenter and the child presenters, but I'm not sure if this is proper thinking. I'd appreciate any help, it seems that the combination of MVP and IoC in winforms isn't exactly well-documented.

    Read the article

  • Castle Windsor Dynamic Property in XML config

    - by haxelit
    I'm trying to set the DataContext on ApplicationMainWindow which is a WPF window. When I set it up in the XML like so it leaves the DataContext null: <!-- View Models --> <component id="mainwindow.viewmodel" type="ProjectTracking.ApplicationMainViewModel, ProjectTracking" inspectionBehavior="none" lifestyle="transient"> </component> <!-- UI Components --> <component id="mainwindow.view" type="ProjectTracking.ApplicationMainWindow, ProjectTracking" inspectionBehavior="none" lifestyle="transient"> <parameters> <DataContext>${mainwindow.viewmodel}</DataContext> </parameters> </component> But if I do it this way via C# it works. _Kernel.Register( ... Component.For<ApplicationMainWindow>() .DynamicParameters( (k,d) => { d["DataContext"] = k[typeof(ApplicationMainViewModel)]; }) ); I'm instantiating my window like so: Window window = _Kernel[typeof(ApplicationMainWindow)] as Window; When I configure windsor via the xml config it leaves my DataContext NULL, but when I configure it via code it works like a charm. Do I need to use code to pull this off, or should it work via XML config ? Thanks, Raul

    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

  • Access custom attribute on method from Castle Windsor interceptor

    - by RobW
    I am trying to access a custom attribute applied to a method within a castle interceptor, e.g.: [MyCustomAttribute(SomeParam = "attributeValue")] public virtual MyEntity Entity { get; set; } using the following code: internal class MyInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { if (invocation.Method.GetCustomAttributes(typeof(MyCustomAttribute), true) != null) { //Do something } } } The interceptor is firing OK when the method is called but this code does not return the custom attribute. How can I achieve this?

    Read the article

  • Castle Windsor: Inject NameValueCollection vs. Dictionary

    - by Aren B
    I've already done many configs where dictionaries are passed into services in the <parameters> block. But what I find myself needing right now is to build a NameValueCollection (allowing multiple entries with the same key) or a Collection of KeyValuePair objects. The reason for this is im not using this dictionary to look up b when given a, im basically using it to pass in a Tuple (pair) of (a,b) to be used later in code. Im kind of new to castle windor and I was wondering how i would go about making a List of KeyValuePair's injected, or a NameValueCollection injected.

    Read the article

  • Windsor Method interception (AOP)

    - by Allan
    Hi there guys, I'm trying to create interceptors for specific methods but I'm having a hard time. I can't bind an aspect to a specific method. I create the faicilities most of examples show but it still doesn't work. Can anyone give me an example of how to do this? I prefer xml conifguration, if possible. Another question, I have this code: <component id="SampleAspect" service="WindsorSample.Aspect.SampleAspect, WindsorSample" type="WindsorSample.Aspect.SampleAspect, WindsorSample"> </component> <component id="HtmlTitleRetriever" type="WindsorSample.DummyObject, WindsorSample"> <parameters> <interceptors> <interceptor>${SampleAspect}</interceptor> </interceptors> </parameters> </component> Then... IWindsorContainer container = new WindsorContainer(new XmlInterpreter()); IDummyObject retriever = container.Resolve<DummyObject>(); retriever.SomeMethod(); This aspect is not executed. Am I missing something? Am I using the wrong approach for aop? Thanks

    Read the article

  • Intercept Properties With Castle Windsor IInterceptor

    - by jeffn825
    Does anyone have a suggestion on a better way to intercept a properties with Castle DynamicProxy? Specifcally, I need the PropertyInfo that I'm intercepting, but it's not directly on the IInvocation, so what I do is: public static PropertyInfo GetProperty(this MethodInfo method) { bool takesArg = method.GetParameters().Length == 1; bool hasReturn = method.ReturnType != typeof(void); if (takesArg == hasReturn) return null; if (takesArg) { return method.DeclaringType.GetProperties() .Where(prop => prop.GetSetMethod() == method).FirstOrDefault(); } else { return method.DeclaringType.GetProperties() .Where(prop => prop.GetGetMethod() == method).FirstOrDefault(); } } Then in my IInterceptor: #region IInterceptor Members public void Intercept(IInvocation invocation) { bool doSomething = invocation.Method.GetProperty().GetCustomAttributes(true).OfType<SomeAttribute>().Count() > 0; } #endregion Thanks.

    Read the article

  • Can't Instantiate Windsor Custom Component Activator

    - by jeffn825
    Hi, I'm getting an exception calling Resolve: KernelException: Could not instantiate custom activator Inner Exception: {"Constructor on type 'MyProj.MyAdapter`1[[MyProj.MyBusinessObject, MyAsm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' not found."} There's definitely a public parameterless constructor there (and I've verified this using reflection at runtime)...so I figure the problem might have to do with the fact that it's generic? I've tried getting the component model object and setting RequiresGenericArguments to true, but that hasn't gotten me anywhere. Any help would be much appreciated! Thanks.

    Read the article

  • How to convert Castle Windsor fluent config to xml

    - by Jonathas Costa
    I would like to convert this fluent approach to xml: container.Register( AllTypes.FromAssemblyNamed("Company.DataAccess") .BasedOn(typeof(IReadDao<>)).WithService.FromInterface(), AllTypes.FromAssemblyNamed("Framework.DataAccess.NHibernateProvider") .BasedOn(typeof(IReadDao<>)).WithService.Base()); Is there any way of doing this, maintaining the simplicity?

    Read the article

  • Setting up Inversion of Control (IoC) in ASP.NET MVC with Castle Windsor

    - by Lirik
    I'm going over Sanderson's Pro ASP.NET MVC Framework and in Chapter 4 he discusses Creating a Custom Controller Factory and it seems that the original method, AddComponentLifeStyle or AddComponentWithLifeStyle, used to register controllers is deprecated now: public class WindsorControllerFactory : DefaultControllerFactory { IWindsorContainer container; public WindsorControllerFactory() { container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle"))); // register all the controller types as transient var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(IController).IsAssignableFrom(t) select t; //[Obsolete("Use Register(Component.For<I>().ImplementedBy<T>().Named(key).Lifestyle.Is(lifestyle)) instead.")] //IWindsorContainer AddComponentLifeStyle<I, T>(string key, LifestyleType lifestyle) where T : class; foreach (Type t in controllerTypes) { container.Register(Component.For<IController>().ImplementedBy<???>().Named(t.FullName).LifeStyle.Is(LifestyleType.Transient)); } } // Constructs the controller instance needed to service each request protected override IController GetControllerInstance(Type controllerType) { return (IController)container.Resolve(controllerType); } } The new suggestion is to use Register(Component.For<I>().ImplementedBy<T>().Named(key).Lifestyle.Is(lifestyle)), but I can't figure out how to present the implementing controller type in the ImplementedBy<???>() method. I tried ImplementedBy<t>() and ImplementedBy<typeof(t)>(), but I can't find the appropriate way to pass int he implementing type. Any ideas?

    Read the article

  • Castle Windsor: Reuse resolved component in OnCreate, UsingFactoryMethod or DynamicParameters

    - by shovavnik
    I'm trying to execute an action on a resolved component before it is returned as a dependency to the application. For example, with this graph: public class Foo : IFoo { } public class Bar { IFoo _foo; IBaz _baz; public Bar(IFoo foo, IBaz baz) { _foo = foo; _baz = baz; } } When I create an instance of IFoo, I want the container to instantiate Bar and pass the already-resolved IFoo to it, along with any other dependencies it requires. So when I call: var foo = container.Resolve<IFoo>(); The container should automatically call: container.Resolve<Bar>(); // should pass foo and instantiate IBaz I've tried using OnCreate, DynamicParameters and UsingFactoryMethod, but the problem they all share is that they don't hold an explicit reference to the component: DynamicParameters is called before IFoo is instantiated. OnCreate is called after, but the delegate doesn't pass the instance. UsingFactoryMethod doesn't help because I need to register these components with TService and TComponent. Ideally, I'd like a registration to look something like this: container.Register<IFoo, Foo>((kernel, foo) => kernel.Resolve<Bar>(new { foo })); Note that IFoo and Bar are registered with the transient life style, which means that the already-resolved instance has to be passed to Bar - it can't be "re-resolved". Is this possible? Am I missing something?

    Read the article

  • Collection of dependencies in castle windsor

    - by jonnii
    I have the following scenario: public class FirstChildService : IChildService { } public class SecondChildService : IChildService { } public class MyService : IService { public MyService(IEnumerable<IChildService> childServices){ ... } } I'm currently registering all the child services and explicitly depending on them in the constructor of MyService, but what I'd like to do is have them all injected as part of a collection. I can think of a few ways to do this: Using a facility Using a component property Registering the collection as a service But all of them feel a bit... icky. What's the best way to manage this? Also, ideally I'd like to do this using the fluent API and constructor injection. I know it's possible to do something similar using properties: http://www.castleproject.org/container/documentation/trunk/usersguide/arrayslistsanddicts.html

    Read the article

  • Castle windsor registration

    - by nivlam
    interface IUserService class LocalUserService : IUserService class RemoteUserService : IUserService interface IUserRepository class UserRepository : IUserRepository If I have the following interfaces and classes, where the IUserService classes have a dependency on IUserRepository. I can register these components by doing something like: container.AddComponent("LocalUserService", typeof(IUserService), typeof(LocalUserService)); container.AddComponent("RemoteUserService", typeof(IUserService), typeof(RemoteUserService)); container.AddComponent("UserRepository", typeof(IUserRepository), typeof(UserRepository)); ... and get the service I want by calling: IUserService userService = container.Resolve<IUserService>("RemoteUserService"); However, if I have the following interfaces and classes: interface IUserService class UserService : IUserService interface IUserRepository class WebUserRepository : IUserRepository class LocalUserRepository : IUserRepository class DBUserRepository : IUserRepository How do I register these components so that the IUserService component can "choose" which repository to inject at runtime? My idea is to allow the user to choose which repository to query from by providing 3 radio buttons (or whatever) and ask the container to resolve a new IUserService each time.

    Read the article

  • castle windsor container not wiring properties correctly

    - by Damian
    I have a class that i want to instantiate thru castle in configuration. public class MyMappings : IMappings { Mapping FirstMapping { get; set; } Mapping SecondMapping { get; set; } OtherType ThirdMapping { get; set; } OtherType FourthMapping { get; set; } Mapping FifthMapping { get; set; } OtherType SixMapping { get; set; } } In my configuration i have the following: ${anothercomponentIDForCompomentOftypeMapping} The problem i am facing is that is assigning the same value to all properties of the same type, completly ignoring the name of the parameter. This properties are optional, i just want to initialize the value for one of them. Thanks,

    Read the article

  • 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

  • Windsor OnCreated for all components

    - by jeffn825
    Hi, How would I go about globally intercepting the creation/resolution of all instances by my container? I know I can do this individually with OnCreated on a per-component basis, but I want to do this globally for all objects resolved by the container. Thanks.

    Read the article

  • Need help configuring Castle-Windsor

    - by Jonathas Costa
    I have these base interfaces and providers in one assembly (Assembly1): public interface IEntity { } public interface IDao { } public interface IReadDao<T> : IDao where T : IEntity { IEnumerable<T> GetAll(); } public class NHibernate<T> : IReadDao<T> where T : IEntity { public IEnumerable<T> GetAll() { return new List<T>(); } } And I have this implementation inside another assembly (Assembly2): public class Product : IEntity { public string Code { get; set; } } public interface IProductDao : IReadDao<Product> { IEnumerable<Product> GetByCode(string code); } public class ProductDao : NHibernate<Product>, IProductDao { public IEnumerable<Product> GetByCode(string code) { return new List<Product>(); } } I want to be able to get IRead<Product> and IProductDao from the container. I am using this registration: container.Register( AllTypes.FromAssemblyNamed("Assembly2") .BasedOn(typeof(IReadDao<>)).WithService.FromInterface(), AllTypes.FromAssemblyNamed("Assembly1") .BasedOn(typeof(IReadDao<>)).WithService.Base()); The IReadDao<Product> works great. The container gives me ProductDao. But if I try to get IProductDao, the container throws ComponentNotFoundException. How can I correctly configure the registration?

    Read the article

  • DI/IoC in Java for a .NET'er used to Castle.Windsor

    - by Ciddan
    Is there a Java DI container that works in a similar way to the most excellent Castle.Windsor container on the .NET side? The Java containers I've had a look at all seem to rely on annotations (Guice) within my services, which I don't dig all that much - I'd like to go POJO all the way if possible. Spring on the other hand can do without the annotations, but it requires a lot of XML. XML configuration != maintainability. One of the really nice things about Castle.Windsor is the wiring you're able to set up in code with Installers, auto wiring based on naming conventions and whatnot. Ideally the container should also support lifecycle management and configuration; i.e. registering components as transient, singleton, pooled etc. Another bonus would be support for interceptors. Any tips would be greatly appreciated.

    Read the article

  • NHibernate (3.1.0.4000) NullReferenceException using Query<> and NHibernate Facility

    - by TigerShark
    I have a problem with NHibernate, I can't seem to find any solution for. In my project I have a simple entity (Batch), but whenever I try and run the following test, I get an exception. I've triede a couple of different ways to perform a similar query, but almost identical exception for all (it differs in which LINQ method being executed). The first test: [Test] public void QueryLatestBatch() { using (var session = SessionManager.OpenSession()) { var batch = session.Query<Batch>() .FirstOrDefault(); Assert.That(batch, Is.Not.Null); } } The exception: System.NullReferenceException : Object reference not set to an instance of an object. at NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, ref IQuery query, ref NhLinqExpression nhQuery) at NHibernate.Linq.NhQueryProvider.Execute(Expression expression) at System.Linq.Queryable.FirstOrDefault(IQueryable`1 source) The second test: [Test] public void QueryLatestBatch2() { using (var session = SessionManager.OpenSession()) { var batch = session.Query<Batch>() .OrderBy(x => x.Executed) .Take(1) .SingleOrDefault(); Assert.That(batch, Is.Not.Null); } } The exception: System.NullReferenceException : Object reference not set to an instance of an object. at NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, ref IQuery query, ref NhLinqExpression nhQuery) at NHibernate.Linq.NhQueryProvider.Execute(Expression expression) at System.Linq.Queryable.SingleOrDefault(IQueryable`1 source) However, this one is passing (using QueryOver<): [Test] public void QueryOverLatestBatch() { using (var session = SessionManager.OpenSession()) { var batch = session.QueryOver<Batch>() .OrderBy(x => x.Executed).Asc .Take(1) .SingleOrDefault(); Assert.That(batch, Is.Not.Null); Assert.That(batch.Executed, Is.LessThan(DateTime.Now)); } } Using the QueryOver< API is not bad at all, but I'm just kind of baffled that the Query< API isn't working, which is kind of sad, since the First() operation is very concise, and our developers really enjoy LINQ. I really hope there is a solution to this, as it seems strange if these methods are failing such a simple test. EDIT I'm using Oracle 11g, my mappings are done with FluentNHibernate registered through Castle Windsor with the NHibernate Facility. As I wrote, the odd thing is that the query works perfectly with the QueryOver< API, but not through LINQ.

    Read the article

  • How can I have a Windsor IoC container that can be shared amongst my classes but not shared across m

    - by Si Keep
    I am building a set of class libraries that produce office open xml based reports and I am using a static Windsor IoC container. My problem is that one possible entry point to the reporting system is via a web front end which means that the reporting systems static IoC Container is being shared amongst multiple web requests which causes exceptions as for each new request the reporting system is trying re-register components in Windsor that were already registered by an earlier request. I dont want to move the registration into the web app global.asax as my reporting system will no longer be stand-alone. How can I have a Windsor IoC container that can be shared amongst my reporting classes but not shared across multiple web requests?

    Read the article

  • Registering IWindsorContainer with ASPNET MVC 2.0 Areas

    - by Bernard Larouche
    I had the following code that was working well before the addition of Areas in MVC 2 : protected override IWindsorContainer CreateContainer(string windsorConfig) { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<IUnitOfWorkFactory>() .ImplementedBy<NHibernateUnitOfWorkFactory>()); container.Register(AllTypes.Of<IController>() .FromAssembly(typeof(HomeController).Assembly) .Configure(t => t.Named(t.Implementation.Name.ToUpper()) .LifeStyle.Is(LifestyleType.Transient))); return container; } It doesn't work anymore with MVC 2.0 Areas feature. Could you guide me through a possible solution Thanks

    Read the article

  • How can I inject an object into an WCF IErrorHandler implementation with Castle Windsor?

    - by Michael Johnson
    I'm developing a set of services using WCF. The application is doing dependency injection with Castle Windsor. I've added an IErrorHandler implementation that is added to services via an attribute. Everything is working thus far. The IErrorHandler object (of a class called FaultHandler is being applied properly and invoked. Now I'm adding logging. Castle Windsor is set up to inject the logger object (an instance of IOurLogger). This is working. But when I try to add it to FaultHandler my logger is null. The code for FaultHandler looks something like this: class FaultHandler : IErrorHandler { public IOurLogger logger { get; set; } public bool HandleError(Exception error) { logger.Write("Exception type {0}. Message: {1}", error.GetType(), error.Message); // Let WCF handle things its way. We only want to log. return false; } public void ProvideFault(Exception error, MessageVersion version, Message fault) { } } This throws it's own exception, since logger is null when HandleError() is called. The logger is being successfully injected into the service itself and is usable there, but for some reason I can't use it in FaultHandler. Update: Here is the relevant part of the Windsor configuration file (edited to protect the innocent): <configuration> <components> <component id="Logger" service="Our.Namespace.IOurLogger, Our.Namespace" type="Our.Namespace.OurLogger, Our.Namespace" /> </components> </configuration>

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8  | Next Page >