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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:12:47+00:00 2026-06-18T10:12:47+00:00

class Entity:IEntityName { #region IEntityName Members public string FirstName { get; set; } public

  • 0
class Entity:IEntityName
{
    #region IEntityName Members

    public string FirstName { get; set; }
    public string LastName { get; set; }
    #endregion
}

public class Person:IPerson
{
    public IEntityName EntityName;

    public Person()
    {
    }

    public Person(IEntityName EntityName)
    {
        this.EntityName = EntityName;
    }

    public string ReverseName()
    {
        return string.Format("Your reverse name is {0} {1}",EntityName.LastName, EntityName.FirstName);
    }

    public override string ToString()
    {
        return string.Format("Name is {0} {1}", EntityName.FirstName, EntityName.LastName);
    }
}

// Main Method

private static string DisplayReverseName(string fName,string lName)
{
        IUnityContainer container = new UnityContainer();
        container.RegisterType<IPerson, Person>().RegisterType<IEntityName,Entity>();

        IEntityName entityName = container.Resolve<IEntityName>();

        entityName.FirstName = fName;
        entityName.LastName = lName;
        var p = container.Resolve<IPerson>(); 
        return p.ReverseName(); //  firstName and lastName are still null
    }

How can I inject the firstName and lastName into Person constructor ?

  • 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-06-18T10:12:48+00:00Added an answer on June 18, 2026 at 10:12 am

    You can use a ParameterOverride like:

    var p = container.Resolve<IPerson>(new ParameterOverride("EntityName", entityName));
    

    This tells unity to supply the entityName instance to the constructor with the parameter named “EntityName”.

    You can find some additional info here: http://msdn.microsoft.com/en-us/library/ff660920(v=pandp.20).aspx

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

Sidebar

Related Questions

consider the following class and struct public class Entity { public IdType Id {get;set;}
Here's my model: public abstract class Entity { public long Id { get; set;
Given the following class public class Entity { public IList<Tag> Tags { get; set;
public abstract class Entity : IEntity { [Key] public virtual int Id { get;
When I run the following class: @Entity public class SurveyResponse { @Id private String
Say I have this class: @Entity @Table(name=PICTURE) public class Picture{ private String category1, category2;
Below is my code class Entity { private int id; private String entityName; private
mI've this entity class: @Entity public class User implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) private
I have an abstract entity: public abstract class Entity extends JPanel implements FocusListener And
I have an entity similar to the below: public class Entity { public List<DateItem>

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.