Config

Posts   
 
    
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 16-Aug-2007 11:08:43   

An application uses a lot of config settings that I store in a cache.

Whats the best method for passing a config object into an entity so that properties in the entity partial class can return calculate values depending on the current config settings?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Aug-2007 20:20:07   

What LLBLGen version are you using? What Template Set (Adapter or SS) are you using?

Are you doing a WebApp o a WinFormsApp?, Do you have a middle Business Layer?

David Elizondo | LLBLGen Support Team
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 19-Aug-2007 22:51:54   

Using v2 adapter.

I have a business layer. Its mainly a webapp, but there is a couple of winforms apps using webservices.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Aug-2007 05:24:47   

One more question: Where do you obtain the current config settings? Is that like a application setting, a user-based setting or a machine setting?

David Elizondo | LLBLGen Support Team
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 20-Aug-2007 09:51:45   

The config settings I am talking about are application settings specific to the instance of the application...so one machine can have multiple instances of the webapp running off the same code base.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 20-Aug-2007 18:45:44   

Hi simon,

Could you explain a little further the scenario you are in? I'm having trouble trying to understand where this can be useful.

simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 21-Aug-2007 00:12:50   

The application has around 100 key value pairs that are stored in the db. These are read into an object when the application starts and is cached for the lifetime of the web app.

What I do is pass this object around my business layer - no problem there.

But as my app has developed a lot of the business logic is now starting to move into partial classes and properties of the entities.

I did create my own EntityFactory with a constructor that accepted the config object. At first this seemed like the solution but I hit the brick wall that it made an entityCollection returned read only. (as you pointed out here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=1028)

I have been wondering how other people get round this. At the moment I am getting a new ConfigEntityCollection in each entity that needs it, but this is obviously very inefficient.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 21-Aug-2007 19:26:25   

What about using the LLBL's Context Class?

simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 04-Sep-2007 00:30:18   

goose wrote:

What about using the LLBL's Context Class?

I can see that a Context class can be used to store an object.

But how do I use this within my Entity Layer?

I need to be able to use the cache from within a property of an entity partial class.

To make up an example. If I have :

ProductEntity.Price ProductEntity.PriceIncVat

ProductEntity.Price is mapped to a column. ProductEntity.PriceIncVat is a property in a partial class. This gets calculated by price and the VAT rate. With the VAT rate never changing during the lifetime of the application it needs to get cached. How can I persist this cache?

I tried to use a custom EntityFactory and pass in a cache object into the constructor, but that didn't work.

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 04-Sep-2007 04:06:12   

Hi,

May be an easy solution is to create a class with shared properties (this properties are the values of your configuration), put this class inside an assembly and add a reference, to this assembly, in the proyects that will need access to the configuration.

simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 04-Sep-2007 09:58:47   

Rogelio wrote:

create a class with shared properties

Good suggestion, but the values themselves need to come from the database and are not constants.

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 04-Sep-2007 13:09:32   

simon831 wrote:

Rogelio wrote:

create a class with shared properties

Good suggestion, but the values themselves need to come from the database and are not constants.

You said: "These are read into an object when the application starts and is cached for the lifetime of the web app."

Then you can read the config when the application starts and put that data into the class.

simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 04-Sep-2007 13:41:38   

read the config when the application starts and put that data into the class.

These config settings are read into the web application at startup, cached and used during the apps lifecycle. That works fine. But the solution is split into layers and I need to pass this cached object into an Entity, so that it can also be used there. Or the Entity layer needs to cache its own version of the config settings.

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 04-Sep-2007 13:49:13   

simon831 wrote:

read the config when the application starts and put that data into the class.

These config settings are read into the web application at startup, cached and used during the apps lifecycle. That works fine. But the solution is split into layers and I need to pass this cached object into an Entity, so that it can also be used there. Or the Entity layer needs to cache its own version of the config settings.

If the entity layer is in the same AppDomain as the other layers that use the config data then you can share the config data with the a class; but if the entity layer is other AppDomain then it need its own set.