Hi
I want to use the Ado.net to Save Data.
I created a class library “Abp.Ado” just ike "Abp.EntityFramework" , then I created a class "AdoRepositoryInstaller.cs"
internal class AdoRepositoryInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For(typeof(IRepository<>)).ImplementedBy(typeof(AdoRepositoryBase<>)).LifestyleTransient(),
Component.For(typeof(IRepository<,>)).ImplementedBy(typeof(AdoRepositoryBase<,>)).LifestyleTransient()
);
}
}
then Create a module "GalaxyDBModule.cs"
public override void Initialize()
{
IocManager.IocContainer.Install(new AdoRepositoryInstaller());
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
}
But running error
Can't create component 'Galaxy.Application.Products.ProductAppService' as it has dependencies to be satisfied.
'Galaxy.Application.Products.ProductAppService' is waiting for the following dependencies:
- Service 'Galaxy.Core.Products.IProuctRepository' which was not registered.
thank you
3 Answer(s)
-
0
Hi,
ProductAppService waiting for IProuctRepository but you're registering IRepository<Prouct>. You can change injected repository to IRepository<Prouct> or implement IProuctRepository by deriving from AdoRepositoryBase<Product>.
-
0
<cite>hikalkan: </cite>
Hi,ProductAppService waiting for IProuctRepository but you're registering IRepository<Prouct>. You can change injected repository to IRepository<Prouct> or implement IProuctRepository by deriving from AdoRepositoryBase<Product>.
This is my implementation class has been deriving from GalaxyRepositoryBase<Product>,but cannot automatic injection
//Galaxy.Ado--ProductRepository.cs public class ProductRepository : GalaxyRepositoryBase, IProuctRepository { public List GetAll(int? id) { var products = new List { new Product { Id = 1 } }; return products; } }
//Galaxy.Ado--GalaxyRepositoryBase.cs public abstract class GalaxyRepositoryBase : AdoRepositoryBase where TEntity : class, IEntity { } public abstract class GalaxyRepositoryBase : GalaxyRepositoryBase where TEntity : class, IEntity { }
When I coded this works good,But I want to automatically inject.
//Galaxy.Ado--GalaxyDataModule.cs [DependsOn(typeof(GalaxyCoreModule), typeof(GalaxyDBModule))] public class GalaxyDataModule : AbpModule { public override void Initialize() { IocManager.IocContainer.Register( Component.For().ImplementedBy().LifestyleTransient() ); IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); } }
I am a Chinese coder, my English is poor. Thank for you .
-
0
Hi,
Is IProuctRepository inherits IRepository? If not, you can inherit ITransientDependency to automatically register to DI system. You can see docs: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection#DocRegisterDependencies">http://www.aspnetboilerplate.com/Pages/ ... pendencies</a>