Castle registering Glass.Mapper.Sc.SitecoreService, database name dependency

168 views
Skip to first unread message

Tom Underhill

unread,
Aug 7, 2014, 11:50:46 AM8/7/14
to glasssite...@googlegroups.com
I'm registering the SitecoreService with Windsor as follows:

Component.For<ISitecoreService>().ImplementedBy<SitecoreService>().LifestyleTransient()
                    .DependsOn(Dependency.OnValue("databaseName","web"))

which works fine.

However, it means that the SitecoreService will always be looking at the same database (in this case web). Really I want to vary this according to the context of the request, so that when in Editing mode I'm accessing the master db, when on the front end I access master etc.

I guess I could wrap the SitecoreService with my own class that implements a parameterless constructor which uses the Sitecore.Context to decide which database name to use. I'd then register this as so:

Component.For<ISitecoreService>().ImplementedBy<MySitecoreService>().LifestylePerWebRequest()

But can anyone think of a better way of doing it?

Cheers,
Tom


Sean Holmesby

unread,
Nov 25, 2014, 2:06:58 PM11/25/14
to glasssite...@googlegroups.com
Instead of registering your own database name for the ISitecoreService with Dependency Injection, are you able to simply use ISitecoreContext instead?
That is practically a ISitecoreService with uses the context database already.

 - Sean
Reply all
Reply to author
Forward
0 new messages