forked from Alex-Dobrynin/Controls.UserDialogs.Maui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instance Is Now Created By Service Provider
This is an experimental implementation to reduce the static instance state code & instead use the service collection to handle resolving user dialogs
- Loading branch information
Showing
6 changed files
with
51 additions
and
16 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
Controls.UserDialogs.Maui/Shared/CustomImplementationInvalidException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text; | ||
|
||
namespace Controls.UserDialogs.Maui; | ||
|
||
public class CustomImplementationInvalidException : Exception | ||
{ | ||
public CustomImplementationInvalidException() | ||
: base($"Custom implementations must implement {nameof(IUserDialogs)}") | ||
{ | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Controls.UserDialogs.Maui; | ||
|
||
public class UserDialogsConfig | ||
{ | ||
private static Type _implementationType = typeof(UserDialogsImplementation); | ||
|
||
public static Type ImplementationType | ||
{ | ||
get => _implementationType; | ||
set | ||
{ | ||
if (!typeof(IUserDialogs).IsAssignableFrom(value)) | ||
{ | ||
throw new CustomImplementationInvalidException(); | ||
} | ||
|
||
_implementationType = value; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Controls.UserDialogs.Maui/Shared/UserDialogsInitializeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Controls.UserDialogs.Maui; | ||
|
||
internal class UserDialogsInitializeService : IMauiInitializeService | ||
{ | ||
public void Initialize(IServiceProvider services) | ||
{ | ||
var userDialogs = services.GetService<IUserDialogs>(); | ||
|
||
UserDialogs.Instance = userDialogs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters