B
Brad Quinn
Friday, no brain power remains...
I have three assemblies; Client, Interface and Implementation.
The Client uses Implementation through remoting.
Client has a reference to Interface, but not to Implementation. Likewise,
Implementation has a reference to Interface, but not to Client.
Interface contains a class that I want to be constructed by some
class+method in Implementation, and nowhere else.
I would make the constructor internal, but the constructing class+method is
in another assembly.
Here is a greatly simplified example;
== Client ==
using System;
using Interface;
namespace Client
{
class Class1
{
// <snip/>
[STAThread]
static void Main(string[] args)
{
string someurl = GetsInitializedSomehow();
IConstructSomeClass foo =
(IConstructSomeClass)Activator.GetObject(
typeof(IConstructSomeClass), someurl );
SomeClass some = foo.Construct( "This is a test" );
}
}
}
== Interface ==
using System;
namespace Interface
{
[Serializable]
public class SomeClass
{
// I want this constructor to be hidden
public SomeClass( string data ) {
this.data = data;
}
private string data;
public string Data
{
get { return data; }
}
}
public interface IConstructSomeClass
{
SomeClass Construct( string data );
}
}
== Implementation ==
using System;
using Interface;
namespace Implementation
{
public class Class1 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToLower() );
}
}
public class Class2 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToUpper() );
}
}
}
I have three assemblies; Client, Interface and Implementation.
The Client uses Implementation through remoting.
Client has a reference to Interface, but not to Implementation. Likewise,
Implementation has a reference to Interface, but not to Client.
Interface contains a class that I want to be constructed by some
class+method in Implementation, and nowhere else.
I would make the constructor internal, but the constructing class+method is
in another assembly.
Here is a greatly simplified example;
== Client ==
using System;
using Interface;
namespace Client
{
class Class1
{
// <snip/>
[STAThread]
static void Main(string[] args)
{
string someurl = GetsInitializedSomehow();
IConstructSomeClass foo =
(IConstructSomeClass)Activator.GetObject(
typeof(IConstructSomeClass), someurl );
SomeClass some = foo.Construct( "This is a test" );
}
}
}
== Interface ==
using System;
namespace Interface
{
[Serializable]
public class SomeClass
{
// I want this constructor to be hidden
public SomeClass( string data ) {
this.data = data;
}
private string data;
public string Data
{
get { return data; }
}
}
public interface IConstructSomeClass
{
SomeClass Construct( string data );
}
}
== Implementation ==
using System;
using Interface;
namespace Implementation
{
public class Class1 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToLower() );
}
}
public class Class2 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToUpper() );
}
}
}