How does object reference work in c# - I tried this, I am currently trying have an object being an reference to another object instance.
I need this in a class I am building
public class TransactionalProducer
{
private readonly IMessageBusProducer producer;
public TransactionalProducer (IMessageBusProducer bus, bool hasTransactionInitialized)
{
producer = bus;
if(hasTransactionInitialized)
{
producer.InitTransactions();
}
producer.BeginTransaction();
}
}
It looks like when I create a new TransactionalProducer
the producer
instance will be set as an new instance, where the values is taken from the function parameter bus
, and not be reference to the one being parsed via the constructor.
How do I make sure that when an new TransactionalProducer
object is being instantiated via the constructor public TransactionalProducer (IMessageBusProducer bus, bool hasTransactionInitialized)
is the producer
set as an object reference to bus
, and not create a new IMessageBusProducer
with the same parameters as function param bus