I have a pretty serious problem. I have an application that has a partial class that is spread out across several folders in my Project. I am trying to create a daughter object that has all the functionality of this object (this is a WCF webservice and I want to make sure that I have all the functionality of that first service before I add on or expand on it). However, for some reason, after I inherit from that object I can't seem to access all the functionality of the first class? I am not sure what I am doing wrong? I can't show any real code segments because it is proprietary, but here is an example.
public partial class OriginalService : IwantThisThing2Work{ //In here the functionality of the Interface is implemented, I just don't feel like writing dummy functionality }
public partial class OriginalService : IwantThisThing2Fail{//In here the functionality of the Interface is implemented, I just don't feel like writing dummy functionality }
public partial class OriginalService : IsomeInterface{//In here the functionality of the Interface is implemented, I just don't feel like writing dummy functionality }
public class Secondservice : OriginalService {//All of the functionality should be in here}
Now, for some reason, I only seem to get the functionality of the first two and not the rest of the functionality. I am not really sure what else I can do? There is not a lot of documentation on the topic that I can think of. The only thing I can think of is maybe there are some dependecies that I am missing or something during compelation.
Any Ideas fellow coders?
You have not provided much information to go on here but I would check that namespaces of all the partial classes are consistent.
OK. I think I figured it out. I forgot to add all of the contract endpoints to my web.config file. I did in fact add the contract's for the two endpoints that I could access.
To be more clear, the person who wrote the original service divided his contract up among several smaller contracts (I guess to separate concern... or SOC). He implemented the contracts by creating one class but dividing it up using partial classes. When I attempted to change the security protocols of the WCF service by implementing WShttpBinding, I only tested the first two contracts he created and I only added those two endpoints. After struggling to get the WSHttpBinding working (setting up a certificate on the server and on my machine... Never did that before) I completely forgot to add the rest of the endpoints. So even though I implemented them in driver of the contracts, they would never be exposed, thus my weeping and nashing of teeth, and fear of Job losses for not being able to perform the simplest of tasks.
Just one more question, what do you guys think of the separation of contracts and implementing them through partial classes? Is that part of some design pattern that I am not aware of?
Thanks,
Idiot Developer.
Related
I'm not so much seeking a specific implementation but trying to figure out the proper terms for what I'm trying to do so I can properly research the topic.
I have a bunch of interfaces and those interfaces are implemented by controllers, repositories, services and whatnot. Somewhere in the start up process of the application we're using the Castle.MicroKernel.Registration.Component class to register the classes to use for a particular interface. For instance:
Component.For<IPaginationService>().ImplementedBy<PaginationService>().LifeStyle.Transient
Recently I became interested in creating an audit trail of every class and method call. There's a few hundred of these classes so writing a proxy class for each one by hand isn't very practical. I could use a template to generate the code but I'd rather not blow up our code base with all that.
So I'm curious if there's some kind of on the fly solution. I know nHibernate creates proxy classes at some point which overlay all the entity classes. Can someone give me some guidance on how I might be able to do something similar here?
Something like:
Component.For<IPaginationService>().ImplementedBy<ProxyFor<PaginationService>>().LifeStyle.Transient
Obviously that won't work because I can only use generics to generalize the types of methods but not the methods themselves. Is there some tricky reflection approach I can use to do this?
You are looking for what Castle Windsor calls interceptors. It's an aspect-oriented way to tackle cross-cutting concerns -- auditing is certainly one of them. See documentation, or an article about the approach:
Aspect oriented programming is an approach that effectively “injects” pieces of code before or after an existing operation. This works by defining an Inteceptor wrapping the logic being invoked then registering it to run whenever a particular set/sub-set of methods are called.
If you want to apply it to many registered services, read more about interceptor selection mechanisms: IModelInterceptorsSelector helps there.
Using PostSharp, things like this can be even done at compile time. This can speed the resulting application, but when used correctly, interceptors are not slow.
At the beginning I know there are couple of similar subject already but decided to create my own as it's a bit more that others.
Think I know how to use interfaces (or not) - how it has to be declared, how class implements it and how to assign object of class which implements interface to this interface.
My main problem is I cannot enforce myself to use them somehow. I am not sure if I really understand when interface has to be used. When I am developing application I noticed that I am not using them or I use them but just simply to declare interface and consume by class as a contract but that's it - I just don't see usage of them later. Those which I much use is inheritance but not interfaces.
So out of what I just wrote the question is more like how to know that in this particular moment I should use them or better in what moment they could be used. How do you do it in your daily business work? Real world examples are welcomed.
I agree with you when you don't have multiple implementations, then it is un-necessary to design the interface and then implement it. It will unnecessarily add a new file to code base. But we find in general practice people create an interface first then implement it. It could be because of 3 main reasons :
For Future : They can see multiple implementation in future, so to make the future implementation secure, lets define the contract during the first implementation.
For Abstraction : Interface will give a small and clear definition of your implementation. You can read the interface and get a quick view/understanding.
For Management : If you are busy with the implementing a component and others have a dependency on your component. So lets quickly design the interface and distribute to them so that they can continue on their part.
In cases of MVC applications where the model is split into separate domain and mapper layers, why would you give each of the mapper classes its own interface?
I have seen a few examples now, some from well respected developers such as the case with this blog, http://site.svn.dasprids.de/trunk/application/modules/blog/models/
I suspect that its because the developers are expecting the code to be re-used by others who may have their own back-ends. Is this the case? Or am I missing something?
Note that in the examples I have seen, developers are not necessarily creating interfaces for the domain objects.
Since interfaces are contracts between classes (I'm kinda assuming that you already know that). When a class expects you to pass an object with as specific interface, the goal is to inform you, that this class instance expect specific method to be executable on said object.
The only case that i can think of, when having a defined interface for data mappers make sense might be when using unit of work to manage the persistence. But even then it would make more sense to simply inject a factory, that can create data mappers.
TL;DR: someone's been overdoing.
P.S.: it is quite possible, that I am completely wrong about this one, since I'm a bit biased on the subject - my mappers contain only 3 (+constructor) public methods: fetch(), store() and remove() .. though names method names tend to change. I prefer to take the retrieval conditions from domain object, as described here.
Before I break my application, my current namespace look something like this:
CompanyAbc.Core
CompanyAbc.AppXyz.Web
CompanyAbc.AppXyz.Business
The CompanyAbc.Core namespace contain common code used by all applications in our company. An example would be a class called "ClientMessage" which we use as a container to carry messages from one tier to another tier (e.g. to abstract out and support showing success or error messages when saving data at the data-tier all the way to the UI-tier)
We are now making the CompanyAbc.AppXyz.Business into a WCF Service. My question is this: What is the best practice for 'sharing' (or not sharing) these base/common entities?
For example, would you:
a) add the [DataContract] attributes directly to classes in the CompanyAbc.Core namespace, even though it has nothing to do with WCF.
CompanyAbc.Core.Entities
ClientMessage.cs
OR
b) create a Data Transfer Object that is an exact copy from the CompanyAbc.Core namespace?
CompanyAbc.Core.Entities
ClientMessage.cs
CompanyAbc.AppXyz.Business.DataContracts
ClientMessageDto.cs
OR
c) Other options?
Another complexity is that we intend to share these assemblies. But to enforce decoupling and not share assemblies/business entities, would you go all out crazy and do something like this?
CompanyAbc.Core
CompanyAbc.Core.Shared.Entities
ClientMessage.cs
CompanyAbc.AppXyz.Web
CompanyAbc.AppXyz.Web.Entities
ClientMessage.cs --> derives from the Core.Shared, or just duplicate code?
CompanyAbc.AppXyz.Business.Entities
ClientMessage.cs --> derives from the Core.Shared, or just duplicate code?
CompanyAbc.AppXyz.Business.DataContracts
ClientMessageDto.cs
I would suggest you make "hierarchy groups" in your assemblies, in order to make it more concise and its use be more intuitive. For instance:
(Taking the #learner example as a base)
ABC.Common (It communicates better the intention)
ABC.Core
ABC.Core.Web
ABC.Core.Windows
ABC.Services.DataContracts
ABC.Services.ServicesContracts
And so on ...
Making a clear hierarchy stimulates its use by the developers, as it fits with the previous assembly already deployed.
Take a look at the .NET assemblies for a reference.
Here is how my namespaces look like, as I used it so far:
ABC.Core
ABC.Data
ABC.Business
ABC.Web;
ABC.Services (common)
ABC.Services.DTO (common)
ABC.Services.Svc1
ABC.Services.Svc1.DTO
ABC.Services.Svc2
ABC.Services.Svc2.DTO
In practice you won't like to have so many shared classes between the services, because they would probably want to be separated one of the other. The better are independent one of the other, the better you can version them, but is true that it would require a bit of duplicated code in the DTO level of each service. Many people use Automapper to project the Core classes into DTOs.
Let me know what you think.
I am developing a WCF web service which has become quite bloated. What techniques do you use to split up the implementation of the contract?
Well you have a couple choices:
First, you could leave it all in one class, but split up into different files using the partial class feature of C#.
Second, you could have the main service class just pass requests off to one of a number of other actual classes that are organized logically.
A third alternative is to consider refactoring to reduce the number of operations you have. Is there actually a use to all of the methods you're exposing?
Finally, you could always split up the service into multiple WCF services.
It's hard to answer your question if you don't give any more information.
Do you mean that your service interface is bloated, or the class implementation? It's hard to answer well, if I don't see the code, or have no other information, anyway, I'll try:
Notice that WCF service is basically just a regular class that implements an interface and has some attributes on its methods. So all the other good OO design rules apply to it. Think about what it does, does it have really single responsibility, if not try to outsource some of that responsibility to other classes that your service depends on. If you need a non-default constructor, use IInstanceProvider to create the service class, and supply it with its dependencies (or if you use Windsor Container use WCF Facility).
If you really want to you can streach your inheritance chain, and move some of the code to a base class. I don't do it, however and always prefer to use composition over inheritance.
Inspect your service contract, and think about how cohesive it really is. Maybe what you should do is to split it, into few smaller, more cohesive services.