Wow, nice =)
I will check this later. It works only for EF or does too for NH ?
Thanks
OMG, really ? haha Sorry, my bad, I missed that. too much hours on this :o
Thank you. bruno
<cite>hikalkan: </cite> I found it :)
It's a typing error: StatusOperacaoRe**<span style="color:#FF0000">s</span>**pository is wrong, it should be StatusOperacaoRepository.
See docs: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection#DocConventionalRegister">http://www.aspnetboilerplate.com/Pages/ ... alRegister</a>
From document:
"Naming conventions are very important here. For example you can change name of PersonAppService to MyPersonAppService or another name which contains 'PersonAppService' postfix since the IPersonAppService has this postfix. But you can not name your service as PeopleService. If you do it, it's not registered for IPersonAppService automatically (It's registered to DI framework but with self-registration, not with interface), so, you should manually register it if you want."
Hi,
Yes, I understood that, I have the implementation class for the Interface as I showed in the code quotes. For this case its ok if I don't use custom repository, but the question is Why works for other services and not this one, as it is the same. And in the future I will add some custom methods there
I will post my code again, I missed something?
Thanks
Repository Interface:
namespace GerenciadorBoletador.Status
{
public interface IStatusOperacaoRepository : IRepository<StatusOperacao>
{
}
}
Service Interface
namespace GerenciadorBoletador.Status
{
public interface IStatusOperacaoService : IApplicationService
{
List<StatusOperacao> GetStatusOperacao();
}
}
Service Implementation
namespace GerenciadorBoletador.Status
{
public class StatusOperacaoService : IStatusOperacaoService
{
private readonly IStatusOperacaoRepository _statusOperacaoRepository;
public StatusOperacaoService(IStatusOperacaoRepository statusOperacaoRepository)
{
_statusOperacaoRepository = statusOperacaoRepository;
}
public List<StatusOperacao> GetStatusOperacao()
{
List<StatusOperacao> result = null;
try
{
result = _statusOperacaoRepository.GetAllList();
}
catch (Exception ex)
{
throw ex;
}
return result;
}
}
}
Repository Implementation
namespace GerenciadorBoletador.NHibernateData.Repositories
{
public class StatusOperacaoRespository : NhRepositoryBase<StatusOperacao>, IStatusOperacaoRepository
{
public StatusOperacaoRespository(ISessionProvider sessionProvider)
: base(sessionProvider)
{
}
}
}
Isn't the implementation my StatusOperacaoRespository ? I don´t have additional methods on this one
I registered like this:
class Program
{
static void Main(string[] args)
{
using (var bootstrapper = new AbpBootstrapper())
{
bootstrapper.Initialize();
Test_Way_1(bootstrapper.IocManager);
}
}
private static void Test_Way_1(IIocManager iocManager)
{
var tester = iocManager.Resolve<Tester>();
tester.Test();
iocManager.Release(tester);
}
}
class Tester : ITransientDependency
{
private readonly IStatusOperacaoService _gopAppService;
public Tester( IStatusOperacaoService gopAppService)
{
_gopAppService = gopAppService;
}
public void Test()
{
var result = _gopAppService.GetStatusOperacao();
}
}
And I have the Module:
[DependsOn(typeof(GerenciadorBoletadorDataModule), typeof(GerenciadorBoletadorApplicationModule))]
public class GerenciadorBoletadorAppModule : AbpModule
{
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
}
}
EDIT: Could this be related with namespace or something like it? because I have other repositories just like that and works fine.
Hello,
Can I hijack this post ? I have the same issue here, but I am not trying to inject IService into Service. My error occurs on IRepository, but its the same as others services that I have that works:
Can't create component 'GerenciadorBoletador.Status.StatusOperacaoService' as it has dependencies to be satisfied.
'GerenciadorBoletador.Status.StatusOperacaoService' is waiting for the following dependencies:
- Service 'GerenciadorBoletador.Status.IStatusOperacaoRepository' which was not registered.
namespace GerenciadorBoletador.Status
{
public interface IStatusOperacaoRepository : IRepository<StatusOperacao>
{
}
}
namespace GerenciadorBoletador.Status
{
public interface IStatusOperacaoService : IApplicationService
{
List<StatusOperacao> GetStatusOperacao();
}
}
namespace GerenciadorBoletador.Status
{
public class StatusOperacaoService : IStatusOperacaoService
{
private readonly IStatusOperacaoRepository _statusOperacaoRepository;
public StatusOperacaoService(IStatusOperacaoRepository statusOperacaoRepository)
{
_statusOperacaoRepository = statusOperacaoRepository;
}
public List<StatusOperacao> GetStatusOperacao()
{
List<StatusOperacao> result = null;
try
{
result = _statusOperacaoRepository.GetAllList();
}
catch (Exception ex)
{
throw ex;
}
return result;
}
}
}
namespace GerenciadorBoletador.NHibernateData.Repositories
{
public class StatusOperacaoRespository : NhRepositoryBase<StatusOperacao>, IStatusOperacaoRepository
{
public StatusOperacaoRespository(ISessionProvider sessionProvider)
: base(sessionProvider)
{
}
}
}
EDIT: Weird stuff, i changed the service to be like this:
private readonly IRepository<StatusOperacao> _statusOperacaoRepository;
public StatusOperacaoService(IRepository<StatusOperacao> statusOperacaoRepository)
{
_statusOperacaoRepository = statusOperacaoRepository;
}
and worked. So, whats wrong with my custom IStatusOperacaoRepository, its just an Interface that extends IRepository<StatusOperacao>
Hello again.
I did some changes on PineNHibernateModule and builded 2 SessionFactory, but I am back to that error :
"Component Late bound NHibernate.ISessionFactory could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name."
I changed NhRepositoryInstaller to receive a custom name:
container.Register(
Component.For<ISessionFactory>()
.Named(_sessionFactoryName)
.UsingFactoryMethod(() => _sessionFactory)
.LifeStyle.Singleton
);
container.Register(
Component.For(typeof(IRepository<>))
.ImplementedBy(typeof(NhRepositoryBase<>))
.LifestyleTransient(),
Component.For(typeof(IRepository<,>))
.ImplementedBy(typeof(NhRepositoryBase<,>))
.LifestyleTransient()
);
So, i have 2 session now, but I am not understanding how can I inject my session to my repository, can you exemplify for me ?
thanks
Hi, thanks for the feedback.
Yes, I think I am going to make some changes on the framework, already did some because I don´t use the Fluent NHibernate. I will try those approach and let you know.
Maybe I will create an SessionFactory dictionary, and inject the specific one on repositories, by name .
I am really new to this that's why I have all those doubts =).
Thanks again. Bruno
Hello hikalkan
You was able to check if this is possible?
I was looking to you SimpleTaskSystem sample, basically I want to have two or more "SimpleTaskSystemDataModule" so on theirs PreInitialize method I have my DB configs.
How can I register that using DI ? The framework repositories will know which ISession to use ?
Thanks
Hello, thanks for the response.
Actually its not 2 DB for the same NHibernate project. let me give you a sample.
I have a financial market system with 3 separated projects: 1 responsible for user authentication and user Data (1 DB) 1 responsible for common searches shared on other systems (1 DB) 1 responsible for the main system operations, like BL, CRUD, etc (1 DB)
Following your samples, I will have 3 different NHibernates class libraries right ? each of them containing my Dependency installers.
So its 3 separated projects that I will use on my asp.net MVC website, How should I install the references there using DI, on the global.asax?
EDIT: Maybe my question is more on the Castle Windsor side. The part that registers the assemblys.
_windsorContainer.Install(FromAssembly.Containing<PineClientesDependencyInstaller>());
i want to install 2 assembly DependencyInstaller, but got an error saying that ISession from nhibernate is already installed.
Its something like this: [http://stackoverflow.com/questions/3351268/what-is-a-correct-approach-to-register-several-instances-for-the-same-type-in-wi])
But if I use that, how do I know which NhRepositoryBase ISession is going to use, DB1 or DB2
Thanks Bruno