How to access class properties through an Interface instance using Unity.WebApi
Is it possible to expose class public properties in different class through IOC. I am creating an instance of Interface but i am not able to access public properties of class. I am using Unity.WebApi for resolving dependencies.
TransactionService Class
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService _fGateway;
public TransactionService(IMbaRepository mbaRepository, IFpnService fpnService)
_mRepository = mRepository;
_fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
//can't use _fGateway to set properties because Interface
// don't implement them
_fGateway.OID = objFUser.OID.ToString();
_fGateway.Amount = objFUser.Amount;
_fGateway.Search(criteria);
FService class
public class FService : IFpService
public string _OID get; set;
public decimal _Amount get; set;
public TransactionResponse Search(string criteria)
TransactionOperationInput _input;
_input = new TransactionOperationInput()
Criteria = _criteria,
OID = _OID,
Amount = _Amount
;
// search transactions
c# oop asp.net-web-api interface inversion-of-control
add a comment |
Is it possible to expose class public properties in different class through IOC. I am creating an instance of Interface but i am not able to access public properties of class. I am using Unity.WebApi for resolving dependencies.
TransactionService Class
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService _fGateway;
public TransactionService(IMbaRepository mbaRepository, IFpnService fpnService)
_mRepository = mRepository;
_fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
//can't use _fGateway to set properties because Interface
// don't implement them
_fGateway.OID = objFUser.OID.ToString();
_fGateway.Amount = objFUser.Amount;
_fGateway.Search(criteria);
FService class
public class FService : IFpService
public string _OID get; set;
public decimal _Amount get; set;
public TransactionResponse Search(string criteria)
TransactionOperationInput _input;
_input = new TransactionOperationInput()
Criteria = _criteria,
OID = _OID,
Amount = _Amount
;
// search transactions
c# oop asp.net-web-api interface inversion-of-control
Are you able to update interface to include missing property? This looks like a design issue.
– Nkosi
Nov 14 '18 at 18:34
Otherwise you would need to cast the interface. This however is a bad design as it tightly couples to implementation concerns which goes against the very reason for injecting abstractions..
– Nkosi
Nov 14 '18 at 18:41
I don't have any control over _input = new TransactionOperationInput() bcause its part of dll file.
– user1263981
Nov 14 '18 at 18:57
I was referring toIFService
interface
– Nkosi
Nov 14 '18 at 18:59
add a comment |
Is it possible to expose class public properties in different class through IOC. I am creating an instance of Interface but i am not able to access public properties of class. I am using Unity.WebApi for resolving dependencies.
TransactionService Class
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService _fGateway;
public TransactionService(IMbaRepository mbaRepository, IFpnService fpnService)
_mRepository = mRepository;
_fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
//can't use _fGateway to set properties because Interface
// don't implement them
_fGateway.OID = objFUser.OID.ToString();
_fGateway.Amount = objFUser.Amount;
_fGateway.Search(criteria);
FService class
public class FService : IFpService
public string _OID get; set;
public decimal _Amount get; set;
public TransactionResponse Search(string criteria)
TransactionOperationInput _input;
_input = new TransactionOperationInput()
Criteria = _criteria,
OID = _OID,
Amount = _Amount
;
// search transactions
c# oop asp.net-web-api interface inversion-of-control
Is it possible to expose class public properties in different class through IOC. I am creating an instance of Interface but i am not able to access public properties of class. I am using Unity.WebApi for resolving dependencies.
TransactionService Class
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService _fGateway;
public TransactionService(IMbaRepository mbaRepository, IFpnService fpnService)
_mRepository = mRepository;
_fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
//can't use _fGateway to set properties because Interface
// don't implement them
_fGateway.OID = objFUser.OID.ToString();
_fGateway.Amount = objFUser.Amount;
_fGateway.Search(criteria);
FService class
public class FService : IFpService
public string _OID get; set;
public decimal _Amount get; set;
public TransactionResponse Search(string criteria)
TransactionOperationInput _input;
_input = new TransactionOperationInput()
Criteria = _criteria,
OID = _OID,
Amount = _Amount
;
// search transactions
c# oop asp.net-web-api interface inversion-of-control
c# oop asp.net-web-api interface inversion-of-control
asked Nov 14 '18 at 18:16
user1263981user1263981
1,19762966
1,19762966
Are you able to update interface to include missing property? This looks like a design issue.
– Nkosi
Nov 14 '18 at 18:34
Otherwise you would need to cast the interface. This however is a bad design as it tightly couples to implementation concerns which goes against the very reason for injecting abstractions..
– Nkosi
Nov 14 '18 at 18:41
I don't have any control over _input = new TransactionOperationInput() bcause its part of dll file.
– user1263981
Nov 14 '18 at 18:57
I was referring toIFService
interface
– Nkosi
Nov 14 '18 at 18:59
add a comment |
Are you able to update interface to include missing property? This looks like a design issue.
– Nkosi
Nov 14 '18 at 18:34
Otherwise you would need to cast the interface. This however is a bad design as it tightly couples to implementation concerns which goes against the very reason for injecting abstractions..
– Nkosi
Nov 14 '18 at 18:41
I don't have any control over _input = new TransactionOperationInput() bcause its part of dll file.
– user1263981
Nov 14 '18 at 18:57
I was referring toIFService
interface
– Nkosi
Nov 14 '18 at 18:59
Are you able to update interface to include missing property? This looks like a design issue.
– Nkosi
Nov 14 '18 at 18:34
Are you able to update interface to include missing property? This looks like a design issue.
– Nkosi
Nov 14 '18 at 18:34
Otherwise you would need to cast the interface. This however is a bad design as it tightly couples to implementation concerns which goes against the very reason for injecting abstractions..
– Nkosi
Nov 14 '18 at 18:41
Otherwise you would need to cast the interface. This however is a bad design as it tightly couples to implementation concerns which goes against the very reason for injecting abstractions..
– Nkosi
Nov 14 '18 at 18:41
I don't have any control over _input = new TransactionOperationInput() bcause its part of dll file.
– user1263981
Nov 14 '18 at 18:57
I don't have any control over _input = new TransactionOperationInput() bcause its part of dll file.
– user1263981
Nov 14 '18 at 18:57
I was referring to
IFService
interface– Nkosi
Nov 14 '18 at 18:59
I was referring to
IFService
interface– Nkosi
Nov 14 '18 at 18:59
add a comment |
1 Answer
1
active
oldest
votes
If you are in control of the services then refactor the interfaces to expose the desired members
public interface IFService
TransactionResponse Search(TransactionOperationInput input);
Make sure the derived implementation has those members
public class FService : IFpService
public TransactionResponse Search(TransactionOperationInput input)
// search transactions
And that the dependent class uses the correct abstraction
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService fGateway;
public TransactionService(IMbaRepository mbaRepository, IFService fService)
_mRepository = mRepository;
fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
TransactionOperationInput input = new TransactionOperationInput()
Criteria = _criteria,
OID = objFUser.OID.ToString(),
Amount = objFUser.Amount,
;
fGateway.Search(input);
//...
//...
Finally make sure the register the appropriate abstractions and implementations with the IoC/DI container.
can IFService expose an object of TransactionOperationInput class which is in dll? I was thinking about having TransactionOperationInput object in TransactionService class where i can set all inputs and then pass it as argument to search method in Fservice.
– user1263981
Nov 14 '18 at 19:11
@user1263981 yes you can do that. That is a more solid design as well.
– Nkosi
Nov 14 '18 at 19:16
@user1263981 check updated answer based on your comment
– Nkosi
Nov 14 '18 at 19:21
@user1263981 also if you find the answers useful remember to vote them up as well.
– Nkosi
Nov 14 '18 at 19:23
Thanks. Search(TransactionOperationInput input) is a private method in TransactionService. TransanctionService implements two methods and it also has one private method which is being called in implemented method with in the class.
– user1263981
Nov 14 '18 at 19:28
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306471%2fhow-to-access-class-properties-through-an-interface-instance-using-unity-webapi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you are in control of the services then refactor the interfaces to expose the desired members
public interface IFService
TransactionResponse Search(TransactionOperationInput input);
Make sure the derived implementation has those members
public class FService : IFpService
public TransactionResponse Search(TransactionOperationInput input)
// search transactions
And that the dependent class uses the correct abstraction
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService fGateway;
public TransactionService(IMbaRepository mbaRepository, IFService fService)
_mRepository = mRepository;
fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
TransactionOperationInput input = new TransactionOperationInput()
Criteria = _criteria,
OID = objFUser.OID.ToString(),
Amount = objFUser.Amount,
;
fGateway.Search(input);
//...
//...
Finally make sure the register the appropriate abstractions and implementations with the IoC/DI container.
can IFService expose an object of TransactionOperationInput class which is in dll? I was thinking about having TransactionOperationInput object in TransactionService class where i can set all inputs and then pass it as argument to search method in Fservice.
– user1263981
Nov 14 '18 at 19:11
@user1263981 yes you can do that. That is a more solid design as well.
– Nkosi
Nov 14 '18 at 19:16
@user1263981 check updated answer based on your comment
– Nkosi
Nov 14 '18 at 19:21
@user1263981 also if you find the answers useful remember to vote them up as well.
– Nkosi
Nov 14 '18 at 19:23
Thanks. Search(TransactionOperationInput input) is a private method in TransactionService. TransanctionService implements two methods and it also has one private method which is being called in implemented method with in the class.
– user1263981
Nov 14 '18 at 19:28
add a comment |
If you are in control of the services then refactor the interfaces to expose the desired members
public interface IFService
TransactionResponse Search(TransactionOperationInput input);
Make sure the derived implementation has those members
public class FService : IFpService
public TransactionResponse Search(TransactionOperationInput input)
// search transactions
And that the dependent class uses the correct abstraction
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService fGateway;
public TransactionService(IMbaRepository mbaRepository, IFService fService)
_mRepository = mRepository;
fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
TransactionOperationInput input = new TransactionOperationInput()
Criteria = _criteria,
OID = objFUser.OID.ToString(),
Amount = objFUser.Amount,
;
fGateway.Search(input);
//...
//...
Finally make sure the register the appropriate abstractions and implementations with the IoC/DI container.
can IFService expose an object of TransactionOperationInput class which is in dll? I was thinking about having TransactionOperationInput object in TransactionService class where i can set all inputs and then pass it as argument to search method in Fservice.
– user1263981
Nov 14 '18 at 19:11
@user1263981 yes you can do that. That is a more solid design as well.
– Nkosi
Nov 14 '18 at 19:16
@user1263981 check updated answer based on your comment
– Nkosi
Nov 14 '18 at 19:21
@user1263981 also if you find the answers useful remember to vote them up as well.
– Nkosi
Nov 14 '18 at 19:23
Thanks. Search(TransactionOperationInput input) is a private method in TransactionService. TransanctionService implements two methods and it also has one private method which is being called in implemented method with in the class.
– user1263981
Nov 14 '18 at 19:28
add a comment |
If you are in control of the services then refactor the interfaces to expose the desired members
public interface IFService
TransactionResponse Search(TransactionOperationInput input);
Make sure the derived implementation has those members
public class FService : IFpService
public TransactionResponse Search(TransactionOperationInput input)
// search transactions
And that the dependent class uses the correct abstraction
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService fGateway;
public TransactionService(IMbaRepository mbaRepository, IFService fService)
_mRepository = mRepository;
fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
TransactionOperationInput input = new TransactionOperationInput()
Criteria = _criteria,
OID = objFUser.OID.ToString(),
Amount = objFUser.Amount,
;
fGateway.Search(input);
//...
//...
Finally make sure the register the appropriate abstractions and implementations with the IoC/DI container.
If you are in control of the services then refactor the interfaces to expose the desired members
public interface IFService
TransactionResponse Search(TransactionOperationInput input);
Make sure the derived implementation has those members
public class FService : IFpService
public TransactionResponse Search(TransactionOperationInput input)
// search transactions
And that the dependent class uses the correct abstraction
public class TransactionService : ITransactionService
private readonly IMRepository _mRepository;
private readonly IFService fGateway;
public TransactionService(IMbaRepository mbaRepository, IFService fService)
_mRepository = mRepository;
fGateway = fService;
private List<Transaction> SearchTransacionsByUser(FUser objFUser)
foreach (var item in something)
TransactionOperationInput input = new TransactionOperationInput()
Criteria = _criteria,
OID = objFUser.OID.ToString(),
Amount = objFUser.Amount,
;
fGateway.Search(input);
//...
//...
Finally make sure the register the appropriate abstractions and implementations with the IoC/DI container.
edited Nov 14 '18 at 19:31
answered Nov 14 '18 at 19:04
NkosiNkosi
116k16130194
116k16130194
can IFService expose an object of TransactionOperationInput class which is in dll? I was thinking about having TransactionOperationInput object in TransactionService class where i can set all inputs and then pass it as argument to search method in Fservice.
– user1263981
Nov 14 '18 at 19:11
@user1263981 yes you can do that. That is a more solid design as well.
– Nkosi
Nov 14 '18 at 19:16
@user1263981 check updated answer based on your comment
– Nkosi
Nov 14 '18 at 19:21
@user1263981 also if you find the answers useful remember to vote them up as well.
– Nkosi
Nov 14 '18 at 19:23
Thanks. Search(TransactionOperationInput input) is a private method in TransactionService. TransanctionService implements two methods and it also has one private method which is being called in implemented method with in the class.
– user1263981
Nov 14 '18 at 19:28
add a comment |
can IFService expose an object of TransactionOperationInput class which is in dll? I was thinking about having TransactionOperationInput object in TransactionService class where i can set all inputs and then pass it as argument to search method in Fservice.
– user1263981
Nov 14 '18 at 19:11
@user1263981 yes you can do that. That is a more solid design as well.
– Nkosi
Nov 14 '18 at 19:16
@user1263981 check updated answer based on your comment
– Nkosi
Nov 14 '18 at 19:21
@user1263981 also if you find the answers useful remember to vote them up as well.
– Nkosi
Nov 14 '18 at 19:23
Thanks. Search(TransactionOperationInput input) is a private method in TransactionService. TransanctionService implements two methods and it also has one private method which is being called in implemented method with in the class.
– user1263981
Nov 14 '18 at 19:28
can IFService expose an object of TransactionOperationInput class which is in dll? I was thinking about having TransactionOperationInput object in TransactionService class where i can set all inputs and then pass it as argument to search method in Fservice.
– user1263981
Nov 14 '18 at 19:11
can IFService expose an object of TransactionOperationInput class which is in dll? I was thinking about having TransactionOperationInput object in TransactionService class where i can set all inputs and then pass it as argument to search method in Fservice.
– user1263981
Nov 14 '18 at 19:11
@user1263981 yes you can do that. That is a more solid design as well.
– Nkosi
Nov 14 '18 at 19:16
@user1263981 yes you can do that. That is a more solid design as well.
– Nkosi
Nov 14 '18 at 19:16
@user1263981 check updated answer based on your comment
– Nkosi
Nov 14 '18 at 19:21
@user1263981 check updated answer based on your comment
– Nkosi
Nov 14 '18 at 19:21
@user1263981 also if you find the answers useful remember to vote them up as well.
– Nkosi
Nov 14 '18 at 19:23
@user1263981 also if you find the answers useful remember to vote them up as well.
– Nkosi
Nov 14 '18 at 19:23
Thanks. Search(TransactionOperationInput input) is a private method in TransactionService. TransanctionService implements two methods and it also has one private method which is being called in implemented method with in the class.
– user1263981
Nov 14 '18 at 19:28
Thanks. Search(TransactionOperationInput input) is a private method in TransactionService. TransanctionService implements two methods and it also has one private method which is being called in implemented method with in the class.
– user1263981
Nov 14 '18 at 19:28
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306471%2fhow-to-access-class-properties-through-an-interface-instance-using-unity-webapi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you able to update interface to include missing property? This looks like a design issue.
– Nkosi
Nov 14 '18 at 18:34
Otherwise you would need to cast the interface. This however is a bad design as it tightly couples to implementation concerns which goes against the very reason for injecting abstractions..
– Nkosi
Nov 14 '18 at 18:41
I don't have any control over _input = new TransactionOperationInput() bcause its part of dll file.
– user1263981
Nov 14 '18 at 18:57
I was referring to
IFService
interface– Nkosi
Nov 14 '18 at 18:59