views:

98

answers:

1

I'm just starting with SubSonic 3 and playing with the SimpleRepository approach. What's the intended lifetime of SimpleRepository classes when used in a desktop application?

Are you expected to keep creating a new instance for everytime you want to touch the database? Should I create an instance to use for each group of database calls that happen together? Should I create one singleton instance when the program starts and use it for everything?

I'm assuming it's one of the second two options, but it's not clear to me if it would be safe to create a single instance and use it for all calls or not. I'll be using an IoC container if that matters.

+3  A: 

There's no harm in keeping the thing alive for the length of the desktop session (make sure you turn off the migration stuff). When I perf-tested the repo I kept one open the whole time and I didn't see any issues with memory leaks - but be sure to close off any readers if you execute them etc etc.

Rob Conery
Thanks Rob! I'm wondering why the comment about "make sure you turn off the migration stuff"? Would the automatic migration stuff be an issue for some reason? Does it cause a lot of overhead on every call or something (as opposed to on just the first call)?
Scott Bussinger
If it's on then every time you talk to the DB it checks your schema and runs a comparison. This is a development-only feature :)
Rob Conery
Uhm.. how can you turn off the "migration stuff"?.. I can't find any docs on this issue
Radu094
In the constructor of the SimpleRepository - set the options to Default. It's all right here:http://subsonicproject.com/docs/Using_SimpleRepository
Rob Conery
one of the reasons I'm using simple repository is because of it's auto migrations, is there a way to force a migration on app start and then put a non-migration repository into the ioc container?
Keivan