I actually made some changes to the code to have the nhibernate
facility configured in code and here how my code looks like:

protected void Application_Start()
                {
                        //var container = new 
WindsorContainer(Server.MapPath("~/Config/
Windsor.config"));
                        IWindsorContainer container = new
WindsorContainer(Server.MapPath("~/Config/Windsor.config"));
                        AreaRegistration.RegisterAllAreas();

                        _application.RegisterFacilities(container);
                        _application.RegisterComponents(container);
                        _application.RegisterViewEngines(ViewEngines.Engines);
                        RegisterRoutes(RouteTable.Routes);
        
ControllerBuilder.Current.SetControllerFactory(container.Resolve<IControllerFactory>());
                        ViewEngines.Engines.Add(new SparkViewFactory());

                }

Application.cs code

public void RegisterFacilities(IWindsorContainer container)
{
        MutableConfiguration facility = new
MutableConfiguration("facility");
        facility.Attributes.Add("id", "nhibernatefacility");
        facility.Attributes.Add("isWeb", "isWeb");
        facility.Attributes.Add("defaultFlushMode", "Commit");
        facility.Attributes.Add("type",
"Castle.Facilities.NHibernateIntegration.NHibernateFacility,
Castle.Facilities.NHibernateIntegration");
        MutableConfiguration factory = facility.CreateChild("factory");
        factory.Attributes.Add("id", "nhibernate.factory");
        MutableConfiguration settings = factory.CreateChild("settings");
        CreateItem(settings, "connection.provider",
"NHibernate.Connection.DriverConnectionProvider");
        CreateItem(settings, "connection.driver_class",
"NHibernate.Driver.SqlClientDriver");
        CreateItem(settings, "connection.connection_string",
"Server=SQLEXPRESS;Initial
Catalog=test;UID=username;PWD=passwrod;Connect Timeout=3600;");
        CreateItem(settings, "dialect",
"NHibernate.Dialect.MsSql2005Dialect");
        CreateItem(settings, "show_sql", "true");
        MutableConfiguration assemblies = factory.CreateChild("assemblies");
        MutableConfiguration assembly = assemblies.CreateChild("assembly");
        assembly.Value = "Myassembly";
        
container.Kernel.ConfigurationStore.AddFacilityConfiguration("nHibernateFacility",
facility);
        container.AddFacility<NHibernateFacility>("nhibernatefacility");
}

public void RegisterComponents(IWindsorContainer container)
{
        container
                .Register(Component.For<IControllerFactory>()
                                                          
.ImplementedBy<WindsorControllerFactory>())

                .Register(AllTypes.Of<IController>()
                                                          
.FromAssembly(typeof(Application).Assembly)
                                                          .Configure(c =>
c.Named(c.ServiceType.Name.ToLowerInvariant())
                                                                                
                  .LifeStyle.Transient));
        RegisterRepositories(container, typeof(ISessionManager).Assembly);
        RegisterRepositories(container,
typeof(PersonRepository).Assembly);
}

private static void RegisterRepositories(IWindsorContainer container,
Assembly assembly)
{
        
container.Register(AllTypes.Of(typeof(IRepository<>)).FromAssembly(assembly)
                .WithService.Select((t, b) => t.GetInterfaces()
                                .Where(i => i.Name.EndsWith("Repository") && 
!i.IsGenericType)));
}

WindsorCollrollerFactory.cs

public class WindsorControllerFactory: IControllerFactory
        {
                #region IControllerFactory Members

                private readonly IKernel _kernel;

                public WindsorControllerFactory(IKernel kernel)
                {
                        _kernel = kernel;
                }

                public IController CreateController(RequestContext 
requestContext,
string controllerName)
                {
                        return
_kernel.Resolve<IController>(controllerName.ToLowerInvariant() +
"controller");
                }

                public void ReleaseController(IController controller)
                {
                        _kernel.ReleaseComponent(controller);
                }

                #endregion
        }

and finally my home controller looks like this:
private readonly IPersonRepository _persons;
                public HomeController(IPersonRepository persons) {
                        _persons = persons;
                }
so now the exception i am getting is "The NHibernateFacility requires
an external configuration" from
container.AddFacility<NHibernateFacility>("nhibernatefacility");
in my application.cs class.

any idea?


On Apr 20, 5:22 pm, Tuna Toksoz <[email protected]> wrote:
> please check the documentation on castle website.
>
> Tuna Toksöz
> Eternal sunshine of the open source mind.
>
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike
>
> On Wed, Apr 21, 2010 at 12:42 AM, José F. Romaniello <[email protected]
>
>
>
> > wrote:
> > I think you are missing the registration of the facility itself...
> > Something like
>
> > container.AddFacility<NHibernateFacility>.. But I'm not sure because I've
> > never used it.
>
> > 2010/4/19 Bobby Fallaha <[email protected]>
>
> > Hey there,
>
> >> I am working on a web application and i am using NHibernate and
> >> Windsor with APS.NET MVC and i am getting a run time error message:
>
> >> Can't create component 'MyProject.Models.PersonRepository' as it has
> >> dependencies to be satisfied.
> >> MyProject.Models.PersonRepository is waiting for the following
> >> dependencies:
>
> >> Services:
> >> - Castle.Facilities.NHibernateIntegration.ISessionManager which was
> >> not registered.
>
> >> Here is how its my web.config file looks like:
>
> >> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
> >>    <session-factory>
> >>      <property name="connection.provider">
> >>        NHibernate.Connection.DriverConnectionProvider
> >>      </property>
> >>      <property name="connection.driver_class">
> >>        NHibernate.Driver.SqlClientDriver
> >>      </property>
> >>      <property name="connection.connection_string">
> >>        Server=.\SQLEXPRESS;Initial
> >> Catalog=test;UID=user;PWD=password;Connect Timeout=3600;
> >>      </property>
> >>      <property name="dialect">
> >>        NHibernate.Dialect.MsSql2005Dialect
> >>      </property>
> >>      <property name="show_sql">
> >>        true
> >>      </property>
> >>      <property name='proxyfactory.factory_class'>
> >>        NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> >> NHibernate.ByteCode.Castle
> >>      </property>
> >>      <property name="adonet.batch_size">16</property>
> >>    </session-factory>
> >>  </hibernate-configuration>
>
> >> The exception is throw from the windsor controller factory when trying
> >> to create the controller:
>
> >> public IController CreateController(RequestContext requestContext,
> >> string controllerName)
> >> {
> >>         return
> >> _kernel.Resolve<IController>(controllerName.ToLowerInvariant() +
> >> "controller");
> >> }
>
> >> what could possible cause this issue?
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "nhusers" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected]<nhusers%[email protected]>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/nhusers?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to