-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve DI services in repositories #214
Comments
I have encountered the same error as you in my Umbraco 10 and 11 solutions. I haven't had the time to test it yet without PetaPoco ORM but could this be helpful? (from the uiomatic docs): |
I'm facing the same problem. |
This should really be resolved by getting the service from the container but this used to work (not sure about newer c# versions) as a workaround
|
I ended up forking this project and injecting namespace UIOMatic
{
public class UIOMaticHelper : IUIOMaticHelper
{
private readonly AppCaches _appCaches;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IScopeProvider _scopeProvider;
private readonly UIOMaticObjectService _uioMaticObjectService;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<IUIOMaticHelper> _logger;
public UIOMaticHelper(AppCaches appCaches,
IHostingEnvironment hostingEnvironment,
IScopeProvider scopeProvider,
UIOMaticObjectService uioMaticObjectService,
IServiceProvider serviceProvider,
ILogger<IUIOMaticHelper> logger)
{
_appCaches = appCaches;
_hostingEnvironment = hostingEnvironment;
_scopeProvider = scopeProvider;
_uioMaticObjectService = uioMaticObjectService;
_serviceProvider = serviceProvider;
_logger = logger;
}
public IUIOMaticRepository GetRepository(UIOMaticAttribute attr, UIOMaticTypeInfo typeInfo)
{
var existingRepositories = _serviceProvider.GetServices<IUIOMaticRepository>();
var existingRepository = existingRepositories.FirstOrDefault(x => x.GetType() == attr.RepositoryType);
if (existingRepository is not null)
{
return (IUIOMaticRepository)existingRepository;
}
return typeof(DefaultUIOMaticRepository).IsAssignableFrom(attr.RepositoryType)
? (IUIOMaticRepository)Activator.CreateInstance(attr.RepositoryType, attr, typeInfo, _scopeProvider, _uioMaticObjectService)
: (IUIOMaticRepository)Activator.CreateInstance(attr.RepositoryType, _scopeProvider);
} Then in my project, I register my builder.Services.AddTransient<IUIOMaticRepository, ISBNRepository>();
builder.Services.AddTransient<IUIOMaticRepository, TitleRepository>(); |
I'm using UIOmatic 5.1.4 with Umbraco 10.4. I have my data in a database separate from the Umbraco DB. I have an Entity Framework project to access data from that database with services registered into DI on startup.
How can I resolve those services in my
AbstractUIOMaticRepository
?Example npoco
Example repository
Currently, I get a Constructor on type
System.MissingMethodException: [Redacted].ISBNRepository not found.
Stack Trace:
The text was updated successfully, but these errors were encountered: