Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 889027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:30:07+00:00 2026-05-15T13:30:07+00:00

I am developing an ecommerce app that is using the UPS shipping webservice. I

  • 0

I am developing an ecommerce app that is using the UPS shipping webservice. I have read that it is good to create a singleton so there is only one instance of a webservice at any time. My code for that is below.

Public Class Ship
    Private Shared sync As New Object()
    Private Shared _Service As New ShipService

    Public Shared ReadOnly Property Service As ShipService
        Get
            If _Service Is Nothing Then
                SyncLock sync
                    If _Service Is Nothing Then
                        _Service = New ShipService
                    End If
                End SyncLock
            End If
            Return _Service
        End Get
    End Property

    Public Shared Function GetInstance() As ShipService
        Return Service()
    End Function
End Class

Here is a snippet from where it will be used.

Public Sub New(ByVal ToAddress As Address, ByVal WeightInLbs As String)
    //Not relevant code
    Ship.Service.UPSSecurityValue = Security
    //More not relevant code 
End Sub

Public Function ProcessShipment() As ShipmentResponse
    Return Ship.Service.ProcessShipment(ShipmentRequest)
End Function

In the line above in the constructor I have to set the UPSSecurityValue of the service. Then later I will call the ProcessShipment function. My question is; Since the webservice is being traeted as a singleton could different instances of the app share that same UPSSecurityValue and could it change between when I set it and when I call ProcessShipment?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:30:08+00:00Added an answer on May 15, 2026 at 1:30 pm

    In the case of what you’re doing, it could definately change between when you call New and set the Security value and when you actually process the shipment. The singleton is shared across all users of your application (within the same web app, that is – if you had multiple copies of this app on your server, they’d each use their own singleton), so all users will share the same data.

    If multiple users run through the application at the same time (or User2 is only 1ms behind):

    User1                           User2
    New (sets security code)
                                    New (sets security code)
    ProcessShipment
                                    ProcessShipment 
    

    Both shipments will process with User2’s security code, which isn’t what you want. The way to do this safely could be to pass the security into the function when you ship the package, and then consume it immediately – if you store it for use later, even a single instruction later, you’re setting yourself up for a race condition where users read each other’s data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.