Async DataPortal call in private field property #1627
Answered
by
rockfordlhotka
JacoJordaan
asked this question in
General
-
I am busy changing my objects to use the async behaviour for dataportal calls to make Blazor webassembly to work. I have tried the LazyGetPropertyAsync option, but this does not work with private backing fields. What approach can I take to get this working? Example of an existing property:
The GetFileContentsString is a function that calls a command object:
|
Beta Was this translation helpful? Give feedback.
Answered by
rockfordlhotka
May 15, 2020
Replies: 1 comment 1 reply
-
I believe this is what you need. public static readonly PropertyInfo<string> BigDataProperty =
RegisterProperty<string>(nameof(BigData), RelationshipTypes.PrivateField);
[NotUndoable, NonSerialized]
private string _name = BigDataProperty.DefaultValue;
public string BigData
{
get
#pragma warning disable CSLA0007 // Evaluate Properties for Simplicity
{
if (string.IsNullOrWhiteSpace(_name))
{
Task.Run(async () =>
{
var result = await DataPortal.FetchAsync<BigDataLoader>(Id);
_name = result.BigData;
OnPropertyChanged(nameof(BigData));
});
return BigDataProperty.DefaultValue;
}
return GetProperty(BigDataProperty, _name);
}
#pragma warning restore CSLA0007 // Evaluate Properties for Simplicity
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
JacoJordaan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe this is what you need.