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

Strong type App Settings and Resources #3539

Closed
enfJoao opened this issue Jan 1, 2025 · 3 comments
Closed

Strong type App Settings and Resources #3539

enfJoao opened this issue Jan 1, 2025 · 3 comments

Comments

@enfJoao
Copy link

enfJoao commented Jan 1, 2025

I'm submitting a

[x] feature request

...about

[x] Content Types or data management

Current Behavior / Expected Behavior

We have strong typing for data through copilot, but not for app settings and resources.

Please implement :)

@iJungleboy
Copy link
Contributor

Actually this already exists ;)

If you auto-generate the base classes (in the co-pilot of the views) the resulting AppCode.Razor.AppRazor have typed App.Settings and App.Resources.

It looks a bit like this

namespace AppCode.Razor
{
  /// <summary>
  /// Base Class for Razor Views which have a typed App but don't use the Model or use the typed MyModel.
  /// </summary>
  public abstract partial class AppRazor: AppRazor<object>
  {
  }

  /// <summary>
  /// Base Class for Razor Views which have a typed App and a typed Model
  /// </summary>
  public abstract partial class AppRazor<TModel>: Custom.Hybrid.RazorTyped<TModel>
  {

    /// <summary>
    /// Typed App with typed Settings & Resources
    /// </summary>
    public new IAppTyped<AppSettings, AppResources> App => _app ??= Customize.App<AppSettings, AppResources>();
    private IAppTyped<AppSettings, AppResources> _app;
  }
}

To use this, simply inherit from that class.

Enjoy ;)

@enfJoao
Copy link
Author

enfJoao commented Jan 4, 2025

Sorry.

Can you provide a clear example on the lines of code needed? For inherit and values.

@iJungleboy
Copy link
Contributor

Sure. Check out some examples on the Blog app. This search will get you a few files that then use App.Razor.Xyz

https://github.com/search?q=repo%3A2sic%2Fapp-blog+apprazor+app.resources&type=code

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

No branches or pull requests

2 participants