Base solution for your next web application
Open Closed

how to Save with Ado.net data? #222


User avatar
0
jesse created

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)
  • User Avatar
    0
    hikalkan created
    Support Team

    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>.

  • User Avatar
    0
    jesse created

    <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<Product>, IProuctRepository
        {
            public List<Product> GetAll(int? id)
            {
                var products = new List<Product> { new Product { Id = 1 } };
                return products;
            }
        }
    
    //Galaxy.Ado--GalaxyRepositoryBase.cs
    public abstract class GalaxyRepositoryBase<TEntity, TPrimaryKey> : AdoRepositoryBase<TEntity, TPrimaryKey>
           where TEntity : class, IEntity<TPrimaryKey>
        {
    
        }
        public abstract class GalaxyRepositoryBase<TEntity> : GalaxyRepositoryBase<TEntity, int>
            where TEntity : class, IEntity<int>
        {
        }
    

    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<IProuctRepository>().ImplementedBy<ProductRepository>().LifestyleTransient()
                    );
                IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
            }
        }
    

    I am a Chinese coder, my English is poor. Thank for you .

  • User Avatar
    0
    hikalkan created
    Support Team

    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>