Skip to content
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

Add IUserTimeZoneService to make it easier to mock UserTimeZoneService #16614

Merged
merged 19 commits into from
Sep 1, 2024

Conversation

hishamco
Copy link
Member

Fixes #16613

@hishamco hishamco requested a review from deanmarcussen August 25, 2024 20:45
@hishamco hishamco changed the title Add IUserTimeZoneService to make it easy to mock UserTimeZoneService Add IUserTimeZoneService to make it easier to mock UserTimeZoneService Aug 25, 2024
Copy link
Member

@MikeAlhayek MikeAlhayek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, add this change to the list of breaking changes in 2.0.

@hishamco
Copy link
Member Author

Renaming the methods will be a breaking changes

@MikeAlhayek
Copy link
Member

Renaming the methods will be a breaking changes

Introducing the interface is already a breaking change :)

@hishamco
Copy link
Member Author

Introducing the interface is already a breaking change :)

It doesn't break anything, anyhow I agree with your suggestions, @deanmarcussen if you don't have any objection I will react to @MikeAlhayek changes

@MikeAlhayek
Copy link
Member

MikeAlhayek commented Aug 26, 2024

It doesn't break anything

@hishamco You are no longer registering the service directly. So now anyone that is injecting that service directly will be broken.

you can instead do this to avoid this breaking change

services.AddScoped<UserTimeZoneService>();
services.AddScoped<IUserTimeZoneService>(sp => sp.GetSetvice<UserTimeZoneService>());

Then add [Obsolete] method over the 3 methods that are not part of the interface so this way people have transition path. In 3.0, we can then just removed the obsolete methods.

Either way, an interface should be little more generic. So since you are introducing an interface, I rather have a cleaner contract

@hishamco
Copy link
Member Author

While 2.0.0 is coming soon, no problem with renaming and introducing a new interface, I will update the PR ASAP

Copy link
Member

@sebastienros sebastienros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wait, I want to understand more about the issue first

@MikeAlhayek
Copy link
Member

@hishamco we triaged this today. @sebastienros @gvkries and myself agreed with my change request. Please make the requested changed and ping me again.

@hishamco
Copy link
Member Author

hishamco commented Aug 29, 2024

@MikeAlhayek does this mean any service we have should have an interface for extensibility?

@MikeAlhayek
Copy link
Member

MikeAlhayek commented Aug 29, 2024

I don't think we should just blindly start creating interfaces because we want to abstract everything. Ideally, this kind of service will be internal so they are not exposed.

But, when we decide we need an interface, preferable we would add a reusable interface without including any implementation info. For example, in this case we want UserTimeZone not CurrentUserTimeZone.

So the interface would look either

public interface IUserTimeZone
{
    ValueTask<ITimeZone> GetAsync(IUser user);

    ValueTask<ITimeZone> UpdateAsync(IUser user);
}

or

public interface ICurrentUserTimeZone
{
    ValueTask<ITimeZone> GetAsync();

    ValueTask<ITimeZone> UpdateAsync();
}

This way we do not repeat the context. In this case, I think we should use IUserTimeZone and keep it generic.

Copy link
Member

@MikeAlhayek MikeAlhayek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hishamco not exactly

@MikeAlhayek MikeAlhayek mentioned this pull request Aug 30, 2024
30 tasks
@MikeAlhayek
Copy link
Member

@hishamco are you planning to finalize this soon as part of 2.0 or should we push this out to 3.0?

@hishamco
Copy link
Member Author

hishamco commented Sep 1, 2024

@MikeAlhayek I just removed the extension methods, for now, we are ready to ship this

@hishamco hishamco requested a review from MikeAlhayek September 1, 2024 17:26
hishamco and others added 3 commits September 1, 2024 20:46
Co-authored-by: Mike Alhayek <mike@crestapps.com>
@hishamco hishamco requested a review from MikeAlhayek September 1, 2024 18:03
Copy link
Member

@MikeAlhayek MikeAlhayek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…erTimeZoneSelector.cs

Co-authored-by: Mike Alhayek <mike@crestapps.com>
@hishamco
Copy link
Member Author

hishamco commented Sep 1, 2024

@MikeAlhayek please check the changes before suggest code change, seems the build is broken

@hishamco hishamco requested a review from MikeAlhayek September 1, 2024 19:41
Copy link
Member

@MikeAlhayek MikeAlhayek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hishamco feel free to merge if you good with my last changs.

@hishamco hishamco merged commit 14ee8f9 into main Sep 1, 2024
12 checks passed
@hishamco hishamco deleted the hishamco/UserTimeZoneService branch September 1, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UserTimeZoneService needs an interface
4 participants