Hi Philip,
Would it be possible to allow multiple FactoryAttributes on a class?
I currently have something similar to the following:
=========================================
[Factory(typeof(IUserAccountDao))]
[Factory(typeof(IUserRoleDao))]
AuthDaoFactory : IFactory<IUserAccountDao>, IFactory<IUserRoleDao>
{
.... code here to return Daos.... however, this code
constructs Dao's that work with one particular DB. All these
Daos here share the same datasource.
}
[Factory(typeof(IOtherDao))]
[Factory(typeof(IFooDao))]
OtherSourceDaoFactory : IFactory<IOtherDao>, IFactory<IFooDao>
{
.... code here returns Daos... however, this code
constructs Dao's that work with another DB other than the one
used in AuthDaoFactory... the Dao's here share the same
database connection string.
}
=========================================
Essentially, what I do next, is the following up at the higher level:
Repository.Resolve < IFooDao >().SomeOperation();
Repository.Resolve < IUserAccountDao >().CreateAccount("abc@abc");
Callers to Resolve() do not know what DaoFactory created the object, nor should the caller care. But, as it stands now, LinFu only allows me to attach one FactoryAttribute to the Factory objects.... this means, I need to add a new factory for each new Dao I create (which I don't want).
Are there any other solutions or workarounds that could solve this issue more elegantly? Or, perhaps, my architecture is whacked. :-/
Many thanks,
Brian
----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com
Hi Philip,
Thanks for the update!
However, I'm not too sure if I like the idea of multiple factory objects being alive in memory, because, architecturally from my point of view it wasn't my intention. And a small detail like this could easily slip through the cracks if it isn't properly documented. (and we know nobody reads the documentation! :P haha)
It would mean, N Daos and N Factory objects. In a system with 25 Daos, 25 Factory objects isn't a big deal, but in my opinion, it isn't the way I had intended my architecture to be designed. Ultimately, my architecture is influenced by LinFu FactoryAttribute details and the way FactoryAttribute is handled which could cause problems later.
After thinking about it a little more, I think my problem is a design flaw in my architecture, because, later, if I decided to add a new Dao, I would need to add a new FactoryAttribute on the factory class + add the new IFactory<IDao> to the factory class extension list which is a two step process. The down side is, if AuthDaoFactory handles the construction of 25 Daos, I would have something like:
[25 Factory Attributes]
AuthDaoFactory: 25 IFactory<IDao>
which doesn't help readability or maintainability.
So, I think I'm going to need to restructure a few things so I could something like:
AuthDaoFactory{
Initialize(){
this.AddHandledType( typeof(IUserAccountDao) );
this.AddHandledType( typeof(IUserRoleDao) );
...etc.
}
}
It's probably a better solution in the long run. Thanks again Philip for all your help. I'm still using LinFu in a lot of places, and it's working out well so far. I really love the ContainerPlugin extensibility points. They were a perfect fit for loading custom SectonHandler information per library. It's awesome.
Thanks again Philip.
-Brian
----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com