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 1097851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:29:30+00:00 2026-05-17T00:29:30+00:00

I need some opinions on choosing which signatures for my web based business layer

  • 0

I need some opinions on choosing which signatures for my web based business layer function:

function void CreateUser(Company UserCompany, string name…)

or

function void CreateUser(int CompanyID, string name…)

If this is a window based I would choose function to take object instead of int because since the company already loaded to the window form, why not just utilize it. Also, I think business layer should take business objects and it’s type safe(preventing accidently pass in 0 or -1).

But on the other hand, if this is a web based application, only id will be loaded to client sites. So it’s kind of redundant to load company object because eventually only companyID will be saved in the dabasebase anyway.

Hopefully my description is not too confusing =P
Thank you for reading.

  • 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-17T00:29:30+00:00Added an answer on May 17, 2026 at 12:29 am

    I think you answered your own question, it depends on the presentation layer you’re using. But when you want to keep this business layer generic, you’ll have to go with the ID.

    Here’s another idea. I personally like to wrap all mutations into classes, that I call commands. You could for instance have an CreateUserCommand that inherits from a base command. This would allow you to use it like this (I’m assuming C# here):

    var command = new CreateUserCommand();
    
    command.UserCompanyId = companyId;
    command.UserName = name;
    
    command.Execute();
    

    When wrapping this logic in a command is very nice pattern. It allows you to put a single use case in a single command. Especially when the amount of logic in a command grows you will appreciate this pattern, but I found it to be very effective for CRUD operations as well.

    This pattern also allows you to abstract the transactional model away in the base class. The base class can wrap a call to execute in a database transaction. Here is an simple implementation:

    public abstract class CommandBase
    {
        public void Execute()
        {
            this.Validate();
    
            using (var conn = ContextFactory.CreateConnection())
            {
                conn.Open();
                using (var transaction = conn.BeginTransaction())
                {
                    using (var db = ContextFactory.CreateContext(conn))
                    {
                        this.ExecuteInternal(db);
    
                        db.SubmitChanges();
                    }
    
                    transaction.Commit();
                }
            }
        }
    
        protected virtual void Validate() { }
    
        protected abstract void ExecuteInternal(YourDataContext context);
    }
    

    And this is what the CreateUserCommand would look like:

    public class CreateUserCommand : CommandBase
    {
        public int UserCompanyId { get; set; }
        public string UserName { get; set; }
    
        protected override void ExecuteInternal(YourDataContext context)
        {
           this.InsertNewUserInDatabase(context);
           this.ReportCreationOfNewUser();
        }
    
        protected override void Validate()
        {
            if (this.UserCompanyId <= 0) 
                throw new InvalidOperationException("Invalid CompanyId");
            if (string.IsNullOrEmpty(this.UserName))
                throw new InvalidOperationException("Invalid UserName");
        }
    
        private void InsertNewUserInDatabase(YourDataContext context)
        {
           db.Users.InsertOnSubmit(new User()
           {
              Name = this.UserName,
              CompanyId = this.CompanyId
           });
        }
    
        private void ReportCreationOfNewUser()
        {
            var message = new MailMessage();
            message.To = Configuration.AdministratorMailAddress;
            message.Body = "User " + this.Name + " was created.";
    
            new SmtpClient().Send(message);
        }
    }
    

    I hope this helps.

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

Sidebar

Related Questions

I need some opinions here. I'm working on a Django project using buildout to
I need some opinions on using PHP to make completely scalable websites.. For instance,
Greetings all. I need to get some opinions from those outside of my work
I was looking for some current opinions on WPF based on their 4.0 release.
I need some opinions on what would be a good approch for using XML
I need some opinions pointers on creating pseudo-filesystems for linux/*nix systems. Firstly when I
I need some opinions on what is the ideal design pattern for a general
Need some regular expressions help. So far I have my code working to allow
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some quick advice I am trying to access a object array but I

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.