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

Allow multiple user pre-configured Configurations for ValueObjects #331

Open
jeffward01 opened this issue Jan 12, 2023 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@jeffward01
Copy link

jeffward01 commented Jan 12, 2023

Describe the feature

Hello all,

Feature Title: Multiple pre-defined configurations

Summary:

By default, Vogen is configured with int type. (Details here)

Current

  • Currently we can only configure (1) configuration scheme, this is the 'default' Configuration scheme.

Proposed

  • It would be nice to allow for multiple configuration schemes,
  • We can define the configuration schemes by Type this is the current implementation strategy
    • It would be nice to also have the ability to define by NamedConfiguration, such as how in DI how you can add a NamedService.

Details

This feature request is an expansion on the existing feature 'Configuration' of Vogen.

##Existing Feature:
In the current implementation, we can utilize an AssemblyInfo.cs class for pre-configuration of Vogen Value Objects, such as:

// This is my AssemblyInfo.cs file
//--------------------
// Code starts below
//--------------------



// Set the defaults for the project

using Vogen;

[assembly:
    VogenDefaults(
        typeof(Guid),
        Conversions.EfCoreValueConverter | Conversions.NewtonsoftJson | Conversions.TypeConverter |
        Conversions.SystemTextJson,
        typeof(ValueObjectValidationException))]

Proposed Feature (Pseudo code)

Please take note of these classes:

  • VogenDefaults <-- Already exists in current implemetantation
  • VogenConfigs <-- suggested new class to add
// This is my AssemblyInfo.cs file
//--------------------
// Code starts below
//--------------------



// Set the defaults for the project

using Vogen;

// [ValueObject]    <--- When this attribute is used, the below config is applied
[assembly:
    VogenDefaults(
        typeof(Guid),
        Conversions.EfCoreValueConverter | Conversions.NewtonsoftJson | Conversions.TypeConverter |
        Conversions.SystemTextJson,
        typeof(ValueObjectValidationException))]

// This example here might be confusing,.... or maybe its handy. 
// [ValueObject<Guid>]     <--- When this attribute is used, the below config is applied
[assembly:
    VogenConfigs(
        typeof(Guid),
    Conversions.TypeConverter | Conversions.NewtonsoftJson ,
        typeof(SomeOtherErrorException))]


// [ValueObject<string>]   <--- When this attribute is used, the below config is applied
[assembly:
    VogenConfigs(
        typeof(string),
        Conversions.SystemTextJson,
        typeof(RandomException))]



//  [ValueObject<int>]       <--- When this attribute is used, the below config is applied
[assembly:
    VogenConfigs(
        typeof(int),
        Conversions.EfCoreValueConverter | Conversions.NewtonsoftJson 
        Conversions.SystemTextJson,
        typeof(OtherException))]

// I don't really like using string literals.  Perhaps we can extract these to a type like what is suggested ==>
// https://github.com/SteveDunn/Vogen/issues/327
//----
// The example implementation would be:
// [ValueObject<int, MyStronglyTypedNameConfig>]  <-- Jeff votes for this


// / [ValueObject<int, MyStronglyTypedNameConfig>]     <--- When this attribute is used, the below config is applied
// or     
//  [ValueObject<int>("MyStronglyTypedName")]     <--- When this attribute is used, the below config is applied
[assembly:
    VogenConfigs(
     "MyStronglyTypedName",  typeof(int),
        Conversions.EfCoreValueConverter | Conversions.NewtonsoftJson | Conversions.TypeConverter |
        Conversions.SystemTextJson,
        typeof(XyzException))]

// / [ValueObject<int, MyOtherStronglyTypedNameConfig>]  <--- When this attribute is used, the below config is applied
// or 
//  [ValueObject<int>("MyOtherStronglyTypedName")]   <--- When this attribute is used, the below config is applied
[assembly:
    VogenConfigs(
     "MyOtherStronglyTypedName",  typeof(int),
        Conversions.EfCoreValueConverter
        Conversions.SystemTextJson,
        typeof(AbcException))]

Please let me know what you guys think, and if there are any questions or suggestions, please feel free to be chatty about it.

Thanks so much!

@jeffward01 jeffward01 added the enhancement New feature or request label Jan 12, 2023
@SteveDunn
Copy link
Owner

Thanks @jeffward01 - certainly something to think about. I'm a bit snowed under at the moment, but this could certainly be a useful addition! Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants