Hello,
I have a custom service and i am using the interface IUserComposer in order to register this service.
public class RegisterGiroCustomService : IUserComposer
{
public void Compose(Composition composition)
{
composition.RegisterFor<IGiroContentService, GiroContentService>();
}
}
I am wondering how i can access to my custom service (IGiroContentService) from a partial view?
For neatness, and if you are using a service in lots of different views then you could create your own version of UmbracoViewPage... and wire things up once...
Umbraco 8 - Access to custom service from view
Hello, I have a custom service and i am using the interface IUserComposer in order to register this service.
I am wondering how i can access to my custom service (IGiroContentService) from a partial view?
Thanks
Hi, may be it will be helpful
Thank you very much. This is exactly what i was looking for.
Hi Oumarou
For neatness, and if you are using a service in lots of different views then you could create your own version of UmbracoViewPage... and wire things up once...
There is some WIP documentation in progress here:
https://github.com/umbraco/UmbracoDocs/compare/v8/ServicesPattern?short_path=cf2726d#diff-cf2726d2ea2b6f60e0225ce051876a55
that has the following example of how to do this:
and then in your view
Anyway it's just a thought... the key to it is anywhere you can get the current reference from a service that's registered with DI by using:
if that helps
regards
Marc
Thank you. i like your approach.
is working on a reply...