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

  • SEARCH
  • Home
  • 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 6816221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:53:59+00:00 2026-05-26T20:53:59+00:00

I wanted to know if this was thread safe/ good practice. My IOC is

  • 0

I wanted to know if this was thread safe/ good practice. My IOC is ninject, everything service layer call is via the default setting (In transient scope I think?).

Question, is instantiating new FileAllocation(loggedonuser,_repo) correct? The best way? What is the best way to do this? This is a domain class that holds logic that could be called from various services, there are usually a few database calls involved, most of the time no persistance is necessary…

Anyway, I call my service method via an interface e.g.

void SaveFile(int reportid, stream file); //Interface name: IReportFileService


public Class FileService: Servicebase, IReportFileService
{

  private readonly IRepoSession _repo;
  public FileService(IUserSession user, IRepoSession repo, IUpdateSession update)
 : base(user,update)
 {
   _repo = repo;
 }

 //save file if users 'counter' is ok..
 public void SaveFile(int reportid, stream file)
 {

  //here I want to instantiate a new class that I store in my domain and store the counters
  //etc and do related db calls to check up relevant values

  //note loggedonuser is a prop on my *base class*
  var userChecks = new FileAllocation(loggedonuser,_repo);
  userChecks.CountEmUp(); //exception is thrown if 0, less than "limit" etc...

  base.update(userChecks.mycompany); //persist
  base.commit(); //base class method includes try, catch block...

 }

}

public class FileAllocation
{

 private readonly IRepoSession _repo;
 private readonly Loggedonuser _user;
 private int CompanyUploads;
 private int UserUploads;
 public Company mycompany;

 public FileAllocation(Loggedonuser user, IRepoSession repo)
 {
  _repo = repo;
  _user = user;
 }

 public void CountEmUp()
 {
   //do error checking,
   //load up other tables can user upload - permissions, count is ok etc...
   // check the upload type if of certain type we cannot proceed - call another method on this class

   //set myCompany variable to new limits etc...

 }

}

Base Service includes a prop, I dont want to instantiate this from other services i.e. more that once, how do I avoid that?

    private LoggedonuserDTO _currentuser = null;
    protected LoggedonuserDTO loggedonuser
    {
        get
        {
            if (_currentuser == null)
            {

                _currentuser = _user.GetCurrentUser(); //make db call here...
            }
            return _currentuser;
        }
    }

@Darin suggested:

public interface IFileAllocation
{
  CountEmUp(Loggedonuser currentuser);
}


//pass in loggedonuser to any method that requires it...
public class FileAllocation: IFileAllocation
{
  CountEmUp(Loggedonuser currentuser)
  { 
   //do whatever here...

  }
}
  • 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-26T20:53:59+00:00Added an answer on May 26, 2026 at 8:53 pm
    var userChecks = new FileAllocation(loggedonuser,_repo);
    

    introduces a strong coupling between the FileService and the FileAllocation classes. If this is not a problem for you then you can leave it that way. Otherwise you could abstract the operations of this FileAllocation class into an interface and then inject it into FileService. This way the FileService is weakly coupled with FileAllocation and could be reused in different contexts and unit tested in isolation.

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

Sidebar

Related Questions

I wanted to know how to use threads in Cocoa. I'm new to this
I'm very new to facebook and wanted to know if this is even possible
I've seen this is various codebases, and wanted to know if this generally frowned
I know this is somewhat of a server question, but I wanted to ask
I wanted to know how PHP would execute this. Order of operations addslashes(strip_tags($record['value'])); Is
I get this warning in my error logs and wanted to know how to
This is something that's I've wanted to know recently, mostly out of curiousity. I'm
This is a question that I've always wanted to know the answer, but never
Thanks for looking at this question. I wanted to know how can I use
This may be very simple question,But please help me. i wanted to know what

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.