-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Extension for umbraco connection string #15186
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
Conversation
Hi there @nikcio, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
This is definitely an improvement! I haven't looked at the code at all, but I had thought it would be possible to add the sqlServerOptionsAction to the new UseUmbracoDatabaseProvider method to emulate the UseSqlServer method? Something like this: services.AddUmbracoDbContext<MovieContext>((serviceProvider, options) =>
{
options.UseUmbracoDatabaseProvider(serviceProvider, x =>
{
x.MigrationsAssembly(typeof(MovieContext).Assembly.GetName().FullName);
});
}); But like I said I haven't looked at the underlying code, so if that is not possible then your method should work just fine to solve the actual issue 🙂 |
That would be nice to have but the reason why I don't think it's a great fit is because the |
Ahh ok, yep that makes sense then 🙂 |
Thank you @nikcio Your PR is a great improvement! Someone from the team will look into it soon! 🎉 |
I feel like we're going to be duplicating code here, any way you can use the existing From looking at the previous PR, noticed things going in public class PersistenceComposer : IComposer
{
public void Compose(IUmbracoBuilder umbracoBuilder)
{
var connectionString = umbracoBuilder.Config.GetUmbracoConnectionString();
}
} I haven't tried out much more than that, but could it be a good start to accomplish what is needed? |
I've re-read the whole thing now, you are calling that |
Hey @nul800sebastiaan I can see this has been laying still for a while now how do you think we should proceed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this has taken a while @nikcio.
As @nul800sebastiaan said there is a bit of duplication here as we have this handling of the data directory both here and in ConfigurationExtensions
, but this update is not making the duplication any worse. However, it looks like the existing extension method could already be used in the code sample you provided.
I.e., with your code we can do this as you've noted:
builder.Services.AddUmbracoDbContext<TestDbContext>((serviceProvider, options) =>
{
ConnectionStrings connectionStrings = serviceProvider.GetUmbracoConnectionString();
options.UseSqlServer(connectionStrings.ConnectionString, x =>
{
x.MigrationsAssembly(typeof(TestDbContext).Assembly.FullName);
});
});
But it's already possible to do:
builder.Services.AddUmbracoDbContext<TestDbContext>((serviceProvider, options) =>
{
var connectionString = builder.Configuration.GetConnectionString(Umbraco.Cms.Core.Constants.System.UmbracoConnectionName);
options.UseSqlServer(connectionString, x =>
{
x.MigrationsAssembly(typeof(TestDbContext).Assembly.FullName);
});
});
So, given that, could you help me out with justifying why it's useful to be able to get this from the service provider too?
Will close this one now. Sorry again for it taking so long such that when I did get to review you have moved on to other things. As far as I can tell - see comment above - this isn't really adding much value in simplifying code. If you, or others, do come back and have a good case that we should continue with it, we can always resurrect. |
Prerequisites
This fixes PR comment
Description
This PR adds the
GetUmbracoConnectionString
extension on theIServiceProvider
. This makes it simple to get the connection string from the provider when using a custom DbContext. (See the PR comment).This new extension method allows for the following code snippet being transformed into a much smaller example:
Before:
After:
This item has been added to our backlog AB#53189