I have jumped from v7 to v9 - I am not sure how Members are dealt with now, in code especially in something like an API or Hangfire code where there isn't a logged on member.
I have been used to using IMember but although it still seems to be available, I'm wondering if MemberIdentityUser is its replacement? Or are members now handled as IPublishedContent?
Any help would be most appreciated, as would pointers to documentation, blogs, tutorials, etc.
It realy depends what exactly you are trying to do as there are several dependencies you can inject depending what you need to do. Could you provide an example of what you were doing before and I may be able to help
Sorry, I think my question is drifting a bit as I do more development!
I have enabled ModelsBuilder because I used that with Umbraco 7 and it was an easy way to get access to properties (as I mentioned above).
However, getting an instance of a ModelsBuilder object is not quite so easy as it now requires a "publishedValueFallback" ... but I don't know what that it is, or where it comes from.
Also, you have to pass it an IPublishedContent version of the data (member). That is what started me wondering whether I should try to only deal with IPublishedContent, or IMember, etc.
Maybe if I could get an explanation of what "publishedValueFallback" is, where it comes from, what it means, etc then maybe that would help me understand it all better. I have searched Google for "publishedValueFallback" and not found any explanation of it.
IMember in Umbraco 9
I have jumped from v7 to v9 - I am not sure how Members are dealt with now, in code especially in something like an API or Hangfire code where there isn't a logged on member.
I have been used to using IMember but although it still seems to be available, I'm wondering if MemberIdentityUser is its replacement? Or are members now handled as IPublishedContent?
Any help would be most appreciated, as would pointers to documentation, blogs, tutorials, etc.
Hi Gordon,
It realy depends what exactly you are trying to do as there are several dependencies you can inject depending what you need to do. Could you provide an example of what you were doing before and I may be able to help
For example, I use this in an API controller (based on UmbracoApiController) to get the current Member (which has been authenticated using OAuth):
However, for me to access custom fields on the Member type, it seems as though I have to convert it to an IMember:
I think you can also convert it to an IPublishedContent to access custom fields.
That doesn't seem to help, in fact it seems to make things more difficult?
Using:
you then seem to have to access properties like:
which isn't as simple as accessing it via IMember:
If I could get the member data as a ModelsBuilder Member, then it would just be:
However, creating a ModelsBuilder Member now requires a fallback value too, but I can't find out anything about what that is!?
This will give you an IMember
You can create an IMember like
Sorry, I think my question is drifting a bit as I do more development!
I have enabled ModelsBuilder because I used that with Umbraco 7 and it was an easy way to get access to properties (as I mentioned above).
However, getting an instance of a ModelsBuilder object is not quite so easy as it now requires a "publishedValueFallback" ... but I don't know what that it is, or where it comes from.
Also, you have to pass it an IPublishedContent version of the data (member). That is what started me wondering whether I should try to only deal with IPublishedContent, or IMember, etc.
Maybe if I could get an explanation of what "publishedValueFallback" is, where it comes from, what it means, etc then maybe that would help me understand it all better. I have searched Google for "publishedValueFallback" and not found any explanation of it.
Hi Gordon,
I don't know if this will help, but I have had to use the fallbacks in render controllers. I just do the following
_variationContextAccessor and _serviceContext and passed to controller contructor using DI
Yes, I have seen that type of code ... but what does it mean?!
If I am writing an API controller which deals with a number of different data types, then what will be supplied by DI?
I guess I'll have to try it and then debug to see what happens!?
Typical Umbraco that it's barely mentioned in the documentation :-(
I believe there is a tryparse method that allows you to pass in a published content object
I've had a look and can't see anything like that.
For now, I think I'll have to just forget about ModelsBuilder and use IMember.
Thanks for your help anyway.
Hi Gordon,
Thanks for reaching out the community.
If you are using ModelsBuilder, then you can use UmbracoContext to cast
IMember
asMember
created by ModelsBuilder.This will give you strongly typed
Member
object from which you can access each property.Click here for example
Paul Seal has a wonderful repository based on Umbraco 9 membership to solve most of the membership related doubts.
Github repo
is working on a reply...