Inter-module communication [on hold]
I have two separate modules , Account and Billing which can work independently of one another. Now my new client wanted a system which need both modules Account and Billinng , but the problem is that some methods of module Account need to be executed when some methods in module Billing are executed. Module Billing contains an interface IBilling which is
public interface IBilling
{
void makeBill(BillEntity bill);
}
A concrete class implementing the above interface
public class Billing:IBilling
{
private BillingRepository _billRepo;
public Billing(BillingRepository billRepo)
{
_billRepo=billRepo;
}
public void makeBill(BillEntity bill)
{
if(bill.isDetailValid())
_billRepo.save(bill);
}
}
Module Account contains an interface ITransaction which is
public interface ITransaction
{
void perform(TransactionEntity transaction);
}
A concrete class implementing the above interface
public class Transaction:ITransaction
{
private TransactionRepository _transactionRepo;
public Transaction(TransactionRepository transactionRepo)
{
_transactionRepo=transactionRepo;
}
public void perform(TransactionEntity transaction)
{
if(transaction.isDetailValid())
_transactionRepo.save(transaction);
}
}
Now what I need is when makeBill method is called in Billing , perform method needs to be called in Transaction too. For this what I am trying is to write another class which implements IBilling interface
public class Mediator:IBilling
{
private ITransaction _transaction;
public Mediator(ITransaction transaction)
{
_transaction=transaction;
}
public void makeBill(BillEntity bill)
{
BillingModule.BillingFactory.getBillingRealImplementation().makeBill(bill);
_transaction.perform(new TransactionEntity());
}
}
For this, I made a factory method in module Billing to return actual implementation for IBilling in module Billing .Unity is used as IOC container.
public class UnityFactory
{
IUnityContainer container = new UnityContainer();
private static IUnityContainer _container = null;
public static IUnityContainer getUnityContainer()
{
if (_container == null)
{
UnityFactory unity = new UnityFactory();
unity.createContainer();
}
return _container;
}
private void createContainer()
{
IUnityContainer container = new UnityContainer();
registerAllTypes(container);
_container = container;
}
private void registerAllTypes(IUnityContainer container)
{
var sssembly = typeof(Billing).Assembly;
container.RegisterTypes(
AllClasses.FromAssemblies(sssembly),
WithMappings.FromAllInterfaces,
WithName.Default,
WithLifetime.ContainerControlled,
overwriteExistingMappings: true);
}
}
public class BillingFactory
{
public static IBilling getBillingRealImplementation()
{
IUnityContainer container = UnityFactory.getUnityContainer();
return container.Resolve<IBilling>();
}
Is this a good approach? If not, can you please suggest me a better approach?
c# design-patterns modules
put on hold as off-topic by Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have two separate modules , Account and Billing which can work independently of one another. Now my new client wanted a system which need both modules Account and Billinng , but the problem is that some methods of module Account need to be executed when some methods in module Billing are executed. Module Billing contains an interface IBilling which is
public interface IBilling
{
void makeBill(BillEntity bill);
}
A concrete class implementing the above interface
public class Billing:IBilling
{
private BillingRepository _billRepo;
public Billing(BillingRepository billRepo)
{
_billRepo=billRepo;
}
public void makeBill(BillEntity bill)
{
if(bill.isDetailValid())
_billRepo.save(bill);
}
}
Module Account contains an interface ITransaction which is
public interface ITransaction
{
void perform(TransactionEntity transaction);
}
A concrete class implementing the above interface
public class Transaction:ITransaction
{
private TransactionRepository _transactionRepo;
public Transaction(TransactionRepository transactionRepo)
{
_transactionRepo=transactionRepo;
}
public void perform(TransactionEntity transaction)
{
if(transaction.isDetailValid())
_transactionRepo.save(transaction);
}
}
Now what I need is when makeBill method is called in Billing , perform method needs to be called in Transaction too. For this what I am trying is to write another class which implements IBilling interface
public class Mediator:IBilling
{
private ITransaction _transaction;
public Mediator(ITransaction transaction)
{
_transaction=transaction;
}
public void makeBill(BillEntity bill)
{
BillingModule.BillingFactory.getBillingRealImplementation().makeBill(bill);
_transaction.perform(new TransactionEntity());
}
}
For this, I made a factory method in module Billing to return actual implementation for IBilling in module Billing .Unity is used as IOC container.
public class UnityFactory
{
IUnityContainer container = new UnityContainer();
private static IUnityContainer _container = null;
public static IUnityContainer getUnityContainer()
{
if (_container == null)
{
UnityFactory unity = new UnityFactory();
unity.createContainer();
}
return _container;
}
private void createContainer()
{
IUnityContainer container = new UnityContainer();
registerAllTypes(container);
_container = container;
}
private void registerAllTypes(IUnityContainer container)
{
var sssembly = typeof(Billing).Assembly;
container.RegisterTypes(
AllClasses.FromAssemblies(sssembly),
WithMappings.FromAllInterfaces,
WithName.Default,
WithLifetime.ContainerControlled,
overwriteExistingMappings: true);
}
}
public class BillingFactory
{
public static IBilling getBillingRealImplementation()
{
IUnityContainer container = UnityFactory.getUnityContainer();
return container.Resolve<IBilling>();
}
Is this a good approach? If not, can you please suggest me a better approach?
c# design-patterns modules
put on hold as off-topic by Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have two separate modules , Account and Billing which can work independently of one another. Now my new client wanted a system which need both modules Account and Billinng , but the problem is that some methods of module Account need to be executed when some methods in module Billing are executed. Module Billing contains an interface IBilling which is
public interface IBilling
{
void makeBill(BillEntity bill);
}
A concrete class implementing the above interface
public class Billing:IBilling
{
private BillingRepository _billRepo;
public Billing(BillingRepository billRepo)
{
_billRepo=billRepo;
}
public void makeBill(BillEntity bill)
{
if(bill.isDetailValid())
_billRepo.save(bill);
}
}
Module Account contains an interface ITransaction which is
public interface ITransaction
{
void perform(TransactionEntity transaction);
}
A concrete class implementing the above interface
public class Transaction:ITransaction
{
private TransactionRepository _transactionRepo;
public Transaction(TransactionRepository transactionRepo)
{
_transactionRepo=transactionRepo;
}
public void perform(TransactionEntity transaction)
{
if(transaction.isDetailValid())
_transactionRepo.save(transaction);
}
}
Now what I need is when makeBill method is called in Billing , perform method needs to be called in Transaction too. For this what I am trying is to write another class which implements IBilling interface
public class Mediator:IBilling
{
private ITransaction _transaction;
public Mediator(ITransaction transaction)
{
_transaction=transaction;
}
public void makeBill(BillEntity bill)
{
BillingModule.BillingFactory.getBillingRealImplementation().makeBill(bill);
_transaction.perform(new TransactionEntity());
}
}
For this, I made a factory method in module Billing to return actual implementation for IBilling in module Billing .Unity is used as IOC container.
public class UnityFactory
{
IUnityContainer container = new UnityContainer();
private static IUnityContainer _container = null;
public static IUnityContainer getUnityContainer()
{
if (_container == null)
{
UnityFactory unity = new UnityFactory();
unity.createContainer();
}
return _container;
}
private void createContainer()
{
IUnityContainer container = new UnityContainer();
registerAllTypes(container);
_container = container;
}
private void registerAllTypes(IUnityContainer container)
{
var sssembly = typeof(Billing).Assembly;
container.RegisterTypes(
AllClasses.FromAssemblies(sssembly),
WithMappings.FromAllInterfaces,
WithName.Default,
WithLifetime.ContainerControlled,
overwriteExistingMappings: true);
}
}
public class BillingFactory
{
public static IBilling getBillingRealImplementation()
{
IUnityContainer container = UnityFactory.getUnityContainer();
return container.Resolve<IBilling>();
}
Is this a good approach? If not, can you please suggest me a better approach?
c# design-patterns modules
I have two separate modules , Account and Billing which can work independently of one another. Now my new client wanted a system which need both modules Account and Billinng , but the problem is that some methods of module Account need to be executed when some methods in module Billing are executed. Module Billing contains an interface IBilling which is
public interface IBilling
{
void makeBill(BillEntity bill);
}
A concrete class implementing the above interface
public class Billing:IBilling
{
private BillingRepository _billRepo;
public Billing(BillingRepository billRepo)
{
_billRepo=billRepo;
}
public void makeBill(BillEntity bill)
{
if(bill.isDetailValid())
_billRepo.save(bill);
}
}
Module Account contains an interface ITransaction which is
public interface ITransaction
{
void perform(TransactionEntity transaction);
}
A concrete class implementing the above interface
public class Transaction:ITransaction
{
private TransactionRepository _transactionRepo;
public Transaction(TransactionRepository transactionRepo)
{
_transactionRepo=transactionRepo;
}
public void perform(TransactionEntity transaction)
{
if(transaction.isDetailValid())
_transactionRepo.save(transaction);
}
}
Now what I need is when makeBill method is called in Billing , perform method needs to be called in Transaction too. For this what I am trying is to write another class which implements IBilling interface
public class Mediator:IBilling
{
private ITransaction _transaction;
public Mediator(ITransaction transaction)
{
_transaction=transaction;
}
public void makeBill(BillEntity bill)
{
BillingModule.BillingFactory.getBillingRealImplementation().makeBill(bill);
_transaction.perform(new TransactionEntity());
}
}
For this, I made a factory method in module Billing to return actual implementation for IBilling in module Billing .Unity is used as IOC container.
public class UnityFactory
{
IUnityContainer container = new UnityContainer();
private static IUnityContainer _container = null;
public static IUnityContainer getUnityContainer()
{
if (_container == null)
{
UnityFactory unity = new UnityFactory();
unity.createContainer();
}
return _container;
}
private void createContainer()
{
IUnityContainer container = new UnityContainer();
registerAllTypes(container);
_container = container;
}
private void registerAllTypes(IUnityContainer container)
{
var sssembly = typeof(Billing).Assembly;
container.RegisterTypes(
AllClasses.FromAssemblies(sssembly),
WithMappings.FromAllInterfaces,
WithName.Default,
WithLifetime.ContainerControlled,
overwriteExistingMappings: true);
}
}
public class BillingFactory
{
public static IBilling getBillingRealImplementation()
{
IUnityContainer container = UnityFactory.getUnityContainer();
return container.Resolve<IBilling>();
}
Is this a good approach? If not, can you please suggest me a better approach?
c# design-patterns modules
c# design-patterns modules
edited 2 hours ago
Dot Net developer
asked yesterday
Dot Net developerDot Net developer
215
215
put on hold as off-topic by Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Heslacher, t3chb0t, Pieter Witvoet, Mast, BCdotWEB
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes