New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with MiniProfiler #44

Closed
JasonGoemaat opened this Issue Jun 10, 2011 · 3 comments

Comments

Projects
None yet
3 participants
@JasonGoemaat

JasonGoemaat commented Jun 10, 2011

I'm interested in using stackoverflow's MiniProfiler and got it working by modifying two lines, but I wondered if there was a way to do it without changing PetaPoco.cs.

First when creating a command (CreateCommand method), PetaPoco uses _factory if present, otherwise uses connection.CreateCommand. Is there a reason not to use connection.CreateCommand all the time? This is one of the changes I needed to make to get MiniProfiler to work.

The second change was adding this line to OpenSharedConnection:
_sharedConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(_sharedConnection as DbConnection);

If PetaPoco had a method for modifying connections it wouldn't have to reference the new assembly. This doesn't seem the best way though... One for Command might be nice to to enable things like global CommandTimeout changes because I don't like the default timeout, but that might be a setting I could add to the database object...

Declaration in PetaPoco.Database:
public static Func<IDbConnection, IDbConnection> ModConnection = null;

And in OpenSharedConnection:
if (ModConnection != null)
_sharedConnection = ModConnection(_sharedConnection);

And in Application_Start:
PetaPoco.Database.ModConnection = delegate(IDbConnection cnn)
{
return MvcMiniProfiler.Data.ProfiledDbConnection.Get(cnn as DbConnection);
};

Since PetaPoco is a single file it might just be better to modify it specifically for this task... Thoughts?

@schotime

This comment has been minimized.

Show comment
Hide comment
@schotime

schotime Jun 15, 2011

Firstly you can pass a connection into PetaPoco. eg. var db = new Database(new SqlConnection(connstring));
There is also a new Timeout property on the Database object so that you can modify the timeout globally or just once.

schotime commented Jun 15, 2011

Firstly you can pass a connection into PetaPoco. eg. var db = new Database(new SqlConnection(connstring));
There is also a new Timeout property on the Database object so that you can modify the timeout globally or just once.

@toptensoftware

This comment has been minimized.

Show comment
Hide comment
@toptensoftware

toptensoftware Jun 17, 2011

Collaborator

I've made some changes that should facilitate this.

  1. A new virtual method OnConnectionOpened that can be used to hook in the MvcMiniProfiler wrapper. (For balance I've also added a virtual OnConnectionClosing)
  2. Command creation is now always done via the connection object.

Please let me know if this works.

Collaborator

toptensoftware commented Jun 17, 2011

I've made some changes that should facilitate this.

  1. A new virtual method OnConnectionOpened that can be used to hook in the MvcMiniProfiler wrapper. (For balance I've also added a virtual OnConnectionClosing)
  2. Command creation is now always done via the connection object.

Please let me know if this works.

@JasonGoemaat

This comment has been minimized.

Show comment
Hide comment
@JasonGoemaat

JasonGoemaat Jun 17, 2011

I wrote a MiniProfilerProviderFactory that works and I just have to change the provider name with my connect string, I'll take a look though... http://bit.ly/lA9RSV

JasonGoemaat commented Jun 17, 2011

I wrote a MiniProfilerProviderFactory that works and I just have to change the provider name with my connect string, I'll take a look though... http://bit.ly/lA9RSV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment