Category: programming

Services.Add => 2 NuGet

If you make a NuGet package for ASP.NET Core  and you make an extension method that calls

Services.AddWhatever

in order to add a Sngleton / Scoped / Transient a

IWhatever =>  Whatever

implementation , please add IWhatever in a separate Nuget .

Why ? Because not all ASP>NET Core projects are made of a single project – and , if someone needs constructor injection with IWhatever in his Business Logic , he must not be forced to add the whole asp.net dependencies for just a IWhatever interface

 

Example: The https://www.nuget.org/packages/Lib.AspNetCore.ServerTiming/   –   it depends upon Microsoft.AspNetCore.Http . But I want just  IServerTiming in a business logic. I do not need also the dependency of  IApplicationBuilder .

( and yes, I have started an issue: https://github.com/tpeczek/Lib.AspNetCore.ServerTiming/issues/19 )

Dependent Framework Versioning

There are multiple ways to version a software . I have used SemanticVersioning ( https://semver.org/ ) and Calendar Versioning (  https://calver.org/ )

Of course , there are others  – please read https://en.wikipedia.org/wiki/Software_versioning   – interesting versioning based on e or PI .

However , I want to propose a new standard :

Dependent Framework Versioning

The major version of a  package is the same of the major version of the framework that is installed on . For the others , can be calver or semver or any other – depending on your choice.

For example , I have made a BlocklyAutomation  package for .NET Core 3 – and it is versioned like

For .NET Core 3  –  https://www.nuget.org/packages/NetCore2Blockly/3.2022.224.16

For .NET Core 5https://www.nuget.org/packages/NetCore2Blockly/5.2022.210.2007

Why is this ? To be easy identified by the users of the package. If I have one user that have an app  on .NET Core 3 and other on .NET Core 5, how can they identify easy what is the latest version for this package  ? With this approach , this can be done just looking on the major version corresponding with the framework version (and yes, I use calver versioning for the rest – yyyy.Md.Hm)

The component programmer

In our days  there are a few occasions when you wrote all the code. I will give 2 examples:

1. Sorting an array

In the late 90 I will do a Quick sort implementation . In our days, the .NET the Array Sort https://docs.microsoft.com/en-us/dotnet/api/system.array.sort?view=net-5.0 has many overloads – pick your poison

2. Make a persistent searchable chat between users of the application

In the 90 I will do an implementation with some network file and/or opening a communication channel ( or, if I were picky , with a database) . Now I have so many options to do the job straight away: databases( SqlServer , Mongo ), communications ( RabbitMQ , SignalR, GRPC ) , languages ( .NET Core for me  ),  architecture ( communicating from one client directly via REST  / GRPC  / WCF /  ) , testing ( MSTEST, XUnit, NUnit…) , compiling and deploying ( GitHub Actions, Azure Devops …). And I do not want to comment about the vast amount of components on Nuget  / Npm .

So in our days counts not only knowing a language and how to do algorithms  , but also knowing a large amount of components that can make your work easy to implement.

Note: For sure, there are also programmers that works to the Google/Bing Search Engine. That are working to innovation at ML  / AI . But I think that the most majority of programmers work for some kind of business – and they are much more productive if they are not a DIY/NIH programmers )

CORS and Programmer Types

There are many types of programmers  – and I would think that I can give an example about how they think differently. 

My example will be with CORS  – that means, accepting requests  from other site(s) . In ASP.NET  , there is a simple way to accept anything ( see tutorial at https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0 )

.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()

And this will be , usually, enough. But , later on, you want to know WHO calls your API – so you add

.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials()

And you think that it is ok – but, at running, an error occurs.

The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the CORS policy by listing individual origins if credentials needs to be supported.

What do you do  ?  Depending on your answer , you are a different kind of programmer. Think – and read below ( or add to the comments )

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1. The Search Programmer

This will google/bing  the error and find ( eventually – or not !  ) https://jasonwatmore.com/post/2020/05/20/aspnet-core-api-allow-cors-requests-from-any-origin-and-with-credentials   . He can fall back to 3 type.

2. The DIY /NIH  Programmer

This will study the CORS protocol for many days . Then he will make his code to solve the problem.

3.. The Framework / Documentation  Programmer

This will think – there have to be a way- the people that have made the framework will be better. So he will read all the functions and he will see https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.cors.infrastructure.corspolicybuilder.setisoriginallowed?view=aspnetcore-5.0 .  He can fall back to 1 type if he cannot find an answer.

What kind of programmer are you ? ( I am the 3rd kind )

You should learn a framework–advice to starting programmers

There are many posts about getting to learn programming. And, of course, all starts with the simple instructions: + , –, % … Then things get somehow more complicated learning modular programming ( or functional, if you do not use global variables …)

After this, you start learning about classes and instances ( Plato is the master here) and overriding and deriving … And maybe some Design Patterns( please, do not talk about Singleton…)

Maybe you learn a bit about Sql( Tables and Views and StoredProcedures) and NoSql …

And after that, you have the basics to write code in any kind of language . But, when you want to start a new application

  1. How you start it  ?
  2. What are the deliverables ?
  3. How to make the Graphical User Interface ?
  4. How to make components ?
  5. and so on …

That’s what a  framework brings to the table: a clear way /  path to do applications. In my case I am talking about .NET Core / C# n(Console applications, Web Applications, Forms application ) . Also, you may want to separate Front End from Backend – Angular or Vue or … could help with that ( and .NET remains just an WebAPI layer) . A framyework ( or 2  – Front End and BackEnd) will teach you how to make possible an application without hassle.

Yes, it is true that the framework is constraining a lot- you do things the framework way, not your way . So what ? You want to get your first application done. The framework is showing you the path – you can walk under it. And you know that, if you do not walk the path, then “hic sunt leones” . You know also that the framework protect you from the problems.

So my advice to young programmers: Learn a framework . Then you could do your first application. And the second. Then you could you start questioning some of the decision of the framework that might not suit your application.

Developing an outlook helper–part 5 from 5–conclusions

Series

 

Developing Outlook helper – introduction

Developing Outlook helper-VBA macro

Developing Outlook helper-C#

Developing Outlook helper – javascript for Office 365

Developing Outlook helper – conclusions

As you see, the developing and testing the Outlook  simple application was made significantly and increasingly difficult . The start point also is more difficult.

Think now about a real application and his verticals also(  saving data / settings, logging, security / authorization , errors …)

What is relatively simple is the upgrade process that is simpler now (  did not mention, but involves just a re-deploy to Microsoft Store)

Another important thing : All the methods to create the application are available. This is beautiful and scaring ….

Developing an outlook helper–part 4 from 5–javascript / Office 365 project

Series

 

Developing Outlook helper – introduction

Developing Outlook helper-VBA macro

Developing Outlook helper-C#

Developing Outlook helper – javascript for Office 365

Developing Outlook helper – conclusions

Develop like it was 201x:

Read about Office Javascript API and try to understand the documentation – https://dev.office.com/docs/add-ins/develop/understanding-the-javascript-api-for-office . Then realize there are some samples where you can start: https://dev.outlook.com/Samples/Addins .

You find Hello World addin (https://github.com/jasonjoh/hello-world-addin) and decide to try it. Download to the PC . The files are

C:\Users\aignat\Downloads\hello-world-addin-master\hello-world-addin-master
.gitattributes
.gitignore
app
HelloWorld.xml
LICENSE.TXT
README.md
app\compose
app\content
app\images
app\read
app\scripts
app\compose\App.css
app\compose\App.js
app\compose\Home
app\compose\Home\Home.css
app\compose\Home\Home.html
app\compose\Home\Home.js
app\content\Office.css
app\images\Close.png
app\read\App.css
app\read\App.js
app\read\Home
app\read\Home\Home.css
app\read\Home\Home.html
app\read\Home\Home.js
app\scripts\jquery-1.9.1.js

You find eventually the code that reads the email data ( in the Home.js ) and displays data(in the Home.html)

You see that this line finds the email

var item = Office.cast.item.toItemRead(Office.context.mailbox.item);

You want to modify the  code. You do not have intellisense helpers, but just documentation.

Test like it was 201x:

SO you have now a bunch of files. How to test it? You cannot test with Outlook. You do not want to deploy to Microsoft store yet. It is testing, right?

You read again what it should be done from       Hello World addin (https://github.com/jasonjoh/hello-world-addin) – and now I am quoting

"

  1. Copy the app directory from the project to your web server.
  2. Open manifest.xml in a text editor and update all instances of https://<your web server> to the base URL of the directory on your web server where you deployed the app directory.
  3. Logon to Outlook Web Access. Click on the gear cog in the upper right corner of the page and click on Manage apps.
  4. On the Manage apps page, click on the ‘+’ icon, select Add from file. Browse to the manifest.xml file included in the project.
  5. Return to the Mail view in Outlook Web Access.
  6. To try the read mode functionality of the add-in, open any message and launch the HelloWorld app from the app bar.

“ – end quoting

So you need

  1. a https server  with FTP account to deploy files
  2. an Outlook 365 account

Once you have those, it is a simple process:

  1. Copy files to the https server.
  2. Goto Outlook 365 settings, load addon from HelloWorld.xml .
  3. Verify if all ok
  4. If not, unload the addon from Office 365.
  5. Modify the files to make the app .
  6. GOTO 1

Deploy like it was 201x:

Pass to the Microsoft Store to get a developer ID and deploy to their server the application.

Developing an outlook helper–part 3 from 5–C# project

Series

 

Developing Outlook helper – introduction

Developing Outlook helper-VBA macro

Developing Outlook helper-C#

Developing Outlook helper – javascript for Office 365

Developing Outlook helper – conclusions

Develop like it was  200x:

Start  Visual Studio. See that you do not have the project. Download the Office addon for VS that create the project. Find the Outlook project – that is a wizard and let you have some choices . Give a name and wait for Visual Studio to load all files.

Those are the files generated by VS2013 ( differs from version to version)

app.config
Properties
Resources
ThisAddIn.cs
ThisAddIn.Designer.cs
ThisAddIn.Designer.xml
FindInEmail.cs
FindInEmail.Designer.cs
FindInEmail.resx
FindInEmailIn.csproj
FindInEmailIn.csproj.user
FindInEmailIn.sln
FindInEmailIn_TemporaryKey.pfx
FindSettings.cs
FindSettings.Designer.cs
FindSettings.resx
.vs\FindInEmailIn
.vs\FindInEmailIn\v14
Properties\AssemblyInfo.cs
Properties\Resources.Designer.cs
Properties\Resources.resx
Properties\Settings.Designer.cs
Properties\Settings.settings

After a while, you realize that you want a button in the ribbon.  You will find eventually the http://www.visualstudioextensibility.com/ site where Carlos Quintero maintains various blog posts about that and understand how to add the ribbon button and how to intercept clock event . Then you wrote more or less the same code as in part 2 :

var m = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem;
MailItem mi = m as MailItem;
if (mi == null)
      return;
//C# same code as in http://msprogrammer.serviciipeweb.ro/2017/01/30/developing-an-outlook-helperpart-2-from-5vba/ 

Test like it was 200x:

Press F5 to run the project. Outlook starts and loads the plugin. So now there are 2 resource hogs on your system: Outlook + Visual Studio. Set break point in VS . Open the email. Find the ribbon in Outlook. Press the button and debug.

Deploy like it was 200x:

Create a VS Setup project and pray

    1. user have the same .NET Framework version that you have developed with
    2. user have the same  Outlook version that you have developed

( There are solution for 1 and 2 to be integrated – but it requires some programming / settings)

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.