I'm writing a generic type to handle the underlying Active Directory objects such as groups, organisational units and users.
I'm also using "manual" dependency injection within my generic interface. I would like to know if, in my situation, which is more appropriate: generic interface or generic method?
Here's a simplified code sample to show you:
public interface IDirectorySource<T> where T : IDirectoryEntry {
IDirectorySearcher<T> Searcher { get; }
CustomSet<T> ToList(); // Related to my question, as I will here only return Searcher.ToList();
}
public interface IDirectorySearcher<T> where T : IDirectoryEntry {
DirectorySearcher NativeSearcher { get; }
CustomSet<T> ToList(); // Related to my question...
}
public sealed class GroupSearcher : IDirectorySearcher<Group> {
public GroupSearcher(DirectoryEntry root, SearchScope scope) {
// Instantiating...
}
public DirectorySearcher NativeSearcher { get; private set; }
public CustomSet<T> ToList() { // That is the point of my question.
// Listing all T objects found in AD...
}
}
public sealed class DirectorySource<T> : IDirectorySource<T> where T : IDirectoryEntry {
public DirectorySource(IDirectorySearcher<T> searcher) {
Searcher = searcher;
}
public IDirectorySearcher<T> Searcher { get; private set; }
public CustomSet<T> ToList() { // Here's the point to my question.
return Searcher.ToList();
}
}
So, here's my point. I would like to make my IDirectorySource
interface non-generic, as I will promote my DirectorySource<T>
class to public. So I would only need to declare a source like so:
GroupSearcher groupSearcher = new GroupSearcher(root, scope);
IDirectorySource groups = new DirectorySource<Group>(groupSearcher);
So I would able to retrive a list of the groups:
groups.ToList(); // Getting all the existing groups in AD here...
But I wonder whether I should let my IDirectorySource<T>
interface generic, or make it non-generic and make my IDirectorySource.ToList()
method generic instead, so I would not need to type my interface, but only the class which would provide me with an instance of my interface.
Would it be better to write my interface like so:
public interface IDirectorySource {
CustomSet<T> ToList<T>();
} // With all the appropriate changes, indeed.
I am aware that this perhaps is not clear enough. Feel free to ask me your questions so that I may help you to help me.
Thanks in advance! =)