Base solution for your next web application

Activities of "cangunaydin"

Hello @ismcagdas, I was working on this weekend and i come up with a solution, so if someone wants to implement this maybe it can be helpful who is reading this.

First of all there is no direct option to extend the generated code from nswag option. However there is one trick you can do by using templates.

  1. You need to download the original template of dtos from this link. https://github.com/RicoSuter/NJsonSchema/tree/master/src/NJsonSchema.CodeGeneration.TypeScript/Templates I have only downloaded "Class.liquid" file since that is the only file i wanted to change.
  2. Then i have added my code after clone method.
  3. i configured my service.config.nswag file by pointing out to get the template files from my ext directory.

that solved my problem. now i can use copyWith method for each dto that is generated.

public copyWith(modifyObject: { [P in keyof this]?: this[P] }): this {
      return Object.assign(Object.create(this.constructor.prototype), { ...this, ...modifyObject });
   }

and if someone is curious about it, i have also found a library that creates immutable objects in an efficient way by using proxy in angular. https://immerjs.github.io/immer/ it supports complex classes but you need to add [immerable] = true attribute to your object, so you can do the same trick if you want to use this library. https://immerjs.github.io/immer/complex-objects

Hello @ismcagdas. To do the option 1, I need to configure service.config.nswag file. Do you know how can i change the configuration? to inherit a custom base class?

"codeGenerators": {
    "openApiToTypeScriptClient": {
      "className": "{controller}ServiceProxy",
      "moduleName": "",
      "namespace": "",
      "typeScriptVersion": 2.7,
      "template": "Angular",
      "promiseType": "Promise",
      "httpClass": "HttpClient",
      "useSingletonProvider": false,
      "injectionTokenType": "InjectionToken",
      "rxJsVersion": 6.0,
      "dateTimeType": "Luxon",
      "nullValue": "Undefined",
      "generateClientClasses": true,
      "generateClientInterfaces": false,
      "generateOptionalParameters": false,
      "exportTypes": true,
      "wrapDtoExceptions": false,
      "exceptionClass": "ApiException",
      "clientBaseClass": null,
      "wrapResponses": false,
      "wrapResponseMethods": [],
      "generateResponseClasses": true,
      "responseClass": "SwaggerResponse",
      "protectedMethods": [],
      "configurationClass": null,
      "useTransformOptionsMethod": false,
      "useTransformResultMethod": false,
      "generateDtoTypes": true,
      "operationGenerationMode": "MultipleClientsFromPathSegments",
      "markOptionalProperties": false,
      "generateCloneMethod": false,
      "typeStyle": "Class",
      "classTypes": [],
      "extendedClasses": [],
      "extensionCode": "service.extensions.ts",
      "generateDefaultValues": true,
      "excludedTypeNames": [],
      "excludedParameterNames": [],
      "handleReferences": false,
      "generateConstructorInterface": true,
      "convertConstructorInterfaceData": false,
      "importRequiredTypes": true,
      "useGetBaseUrlMethod": false,
      "baseUrlTokenName": "API_BASE_URL",
      "queryNullValue": "",
      "inlineNamedDictionaries": false,
      "inlineNamedAny": false,
      "templateDirectory": null,
      "typeNameGeneratorType": null,
      "propertyNameGeneratorType": null,
      "enumNameGeneratorType": null,
      "serviceHost": null,
      "serviceSchemes": null,
      "output": "../src/shared/service-proxies/service-proxies.ts"
    },

if i give clientBaseClass: "ObjectCopier" and implement the class in "service.extensions.ts". It is creating it only on service classes. not on dtos, do you know a way to do it?

class ObjectCopier {
   public copyWith(modifyObject: { [P in keyof this]?: this[P] }): this {
      return Object.assign(Object.create(this.constructor.prototype), { ...this, ...modifyObject });
   }
}

Hello @ismcagdas, I don't think someone will reply a solution for this. I know that there is no one right solution for this problem, but i was thinking maybe you come up with sth similar in the community or support. Should i raise the same question on abp commercial support instead? Since I use abp on another project and ddd is more focused on that framework?

yes silly me, thanks for the answer and sorry to take your time.

Hello @ismcagdas, Thank you for the answer actually invoicing is bad naming coming from me i believe. maybe i should say EXTERNAL SYSTEMS instead or sth more convenient for the naming.

The module i am gonna implement is gonna be responsible for the implementations. So factory classes gonna be in EXTERNAL SYSTEMS. interfaces are gonna be inside CORE.

in this way i can use the interfaces from CORE and implement it on the EXTERNAL SYSTEMS.

EXTERNAL SYSTEMS can be dependent on different invoicing modules like Oracle Netsuite Module that i have created or Fortnox or different nuget packages for different invoicing systems. So i will do the decision for implementation at this module by using the interfaces from CORE.

sth like this maybe more convenient.

Note: I only created oracle netsuite project not the EXTERNAL SYSTEMS project yet :)

So i think what i want to ask is, Since i am gonna do conditional dependency resolve, my core project needs to know about what kind of interfaces i am going to use. here is some drawing i made for it.

so the question is, is it possible to use only IInvoicingService inside core somehow?

Sorry for lots of questions, I am also learning on the way and i really appreciate the assistance and help.

Sure, I am posting couple of drawings here to show what i mean

here with the red dashes is what i am trying to create and when i say infrastructure project i am referring to

and this one https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

so basically infrastructure for me is all the implementations take place with the abstractions of your domain model. So since application service also dependent on your core project (domain model) i was thinking, is it possible to do the implementation on application layer? Or what will be the problems with it? Cause when i think about it, some tenants don't need to use invoicing at all. Isn't this a business rule to choose which invoicing platform should the tenant use?

At the same time some tenants in aspnet zero don't need to use payment services at all, but still implementations are on the domain model and it's strictly connected to your domain. Actually what i am trying to find out is, i understand your payment can not have general abstraction for stripe and paypal, but what if it has, how smart would be to do the implementation on application service? or what kind of problems would it bring?

Hello @ismcagdas, thanks for your answer, what do you think about application service question? why shouldn't i reference my oracle netsuite project directly to application service and create the implementation over there like EPPlus you did? what can be the benefit of creating the seperate project?

Hello @ismcagdas, I looked at your suggestion and the problem is definitely from the overrides of Date.ToString()

  Date.prototype.toString = function () {
            let value = DateTime.fromJSDate(this)
                .setLocale('en')
                .setZone(abp.timing.timeZoneInfo.iana.timeZoneId)
                .toString();
            return value;
        };

        DateTime.prototype.toString = function () {
            let date = this.setLocale('en').setZone(abp.timing.timeZoneInfo.iana.timeZoneId) as DateTime;
            return date.toISO();
        };

But the thing that is suggested (dateSerializationFormat) is not applicable to RangeSelector cause there is no option for date serialization in the component. you can check that out from the link below. https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxRangeSelector/

I have raised a question in devexreme support for this, waiting for an answer now, on the meantime i decided not to use devextreme components since it is making more trouble for me.Or i should make a choice between ngx-date or devextreme components. Since my app is using ngx-datepicker everywhere i don't want to go through big transition and replace every ngx-datepicker component. I will give more information when i get a reply from devexpress and in the meantime if anz got another solution for it, you can let me know.

Thank you @ismcagdas i am closing this ticket and i will follow the issue from the link you provided.

Hello @ismcagdas thanks for your answers it was helpful. I am closing this issue and will wait for your solutions for module unnecessary usages i have other questions but i will raise it on another ticker since it is not related with this thanks again.

Showing 11 to 20 of 133 entries