-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f59453a
commit cddab53
Showing
8 changed files
with
141 additions
and
48 deletions.
There are no files selected for viewing
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
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,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using CommonServiceLocator; | ||
|
||
namespace Emerald.Helpers.Services; | ||
|
||
//Bruh I can't get uno services to work. help me. | ||
|
||
public class ServiceProviderLocator : IServiceLocator | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public ServiceProviderLocator(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
|
||
public object GetService(Type serviceType) | ||
{ | ||
return _serviceProvider.GetService(serviceType) | ||
?? throw new InvalidOperationException($"Service of type {serviceType.FullName} not found."); | ||
} | ||
|
||
public object GetInstance(Type serviceType) | ||
{ | ||
return GetService(serviceType); | ||
} | ||
|
||
public object GetInstance(Type serviceType, string key) | ||
{ | ||
// For simplicity, ignoring `key`. | ||
return GetInstance(serviceType); | ||
} | ||
|
||
public IEnumerable<object> GetAllInstances(Type serviceType) | ||
{ | ||
// I asked AI and told me this | ||
var services = (IEnumerable<object>)_serviceProvider.GetService(typeof(IEnumerable<>).MakeGenericType(serviceType)); | ||
return services ?? Array.Empty<object>(); | ||
} | ||
|
||
public TService GetInstance<TService>() | ||
{ | ||
return (TService)GetInstance(typeof(TService)); | ||
} | ||
|
||
public TService GetInstance<TService>(string key) | ||
{ | ||
return (TService)GetInstance(typeof(TService), key); | ||
} | ||
|
||
public IEnumerable<TService> GetAllInstances<TService>() | ||
{ | ||
return (IEnumerable<TService>)GetAllInstances(typeof(TService)); | ||
} | ||
} |
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